SlideShare a Scribd company logo
PHP Functions
jigar makhija
Date Functions
Date, getdate, setdate, Checkdate, time, mktime
<?php
$time = time();
print("Current Timestamp: ".$time);
?>
<?php
$bool = checkdate(12, 12, 2005);
if($bool){
print("Given date is valid");
}else{
print("Given date is invalid");
}
?>
DATE
<?php
$date = date("D M d Y");
print("Date: ".$date);
?>
TIME
<?php
$timestamp = mktime();
print($timestamp);
?>
Setting and Getting Dates
<?php
//Creating a date
$date = new DateTime();
//Setting the date
date_date_set($date, 2019, 07, 17);
print("Date: ".date_format($date, "Y/m/d"));
?>
<?php
//Date string
$date_string = "25-09-1989";
//Creating a DateTime object
$date_time_Obj = date_create($date_string);
print("Original Date: ".date_format($date_time_Obj,
"Y/m/d"));
print("n");
//Setting the date
$date = date_date_set($date_time_Obj, 2015, 11, 25 );
print("Modified Date: ".date_format($date, "Y/m/d"));
<?php
//Creating a DateTime object
$date_time_Obj = date_create("25-09-1989");
//formatting the date/time object
$format = date_format($date_time_Obj, "y-d-
m");
print("Date in yy-dd-mm format: ".$format);
?>
<?php
$info = getdate();
print_r($info);
?>
Variable Function
Gettype, settype, isset, unset, strval, floatval, intval, print_r
$a = 3;
echo gettype($a) . "<br>";
$b = 3.2;
echo gettype($b) . "<br>";
$a = array("red", "green", "blue");
print_r($a);
echo "<br>";
$b = array("Peter"=>"35", "Ben"=>"37",
"Joe"=>"43");
print_r($b);
<?php
$a = "32"; // string
settype($a, "integer"); // $a is now integer
$b = 32; // integer
settype($b, "string"); // $b is now string
$c = true; // boolean
settype($c, "integer"); // $c is now integer (1)
?>
$a = 0;
// True because $a is set
if (isset($a)) {
echo "Variable 'a' is set.<br>";
}
Variable Function
Gettype, settype, isset, unset, strval, floatval, intval, print_r
$a = "Hello world!";
echo "The value of variable 'a' before unset: " . $a . "<br>";
unset($a);
echo "The value of variable 'a' after unset: " . $a;
?>
$b = 3.2;
echo intval($b) . "<br>";
$c = "32.5";
echo intval($c) . "<br>";
$b = "1234.56789Hello";
echo floatval($b) . "<br>";
$c = "Hello1234.56789";
echo floatval($c) . "<br>";
$a = "1234.56789";
echo doubleval($a) .
"<br>";
$b = "1234.56789Hello";
echo doubleval($b) .
"<br>";
$d = "Hello1234.56789";
echo strval($d) . "<br>";
$e = 1234;
echo strval($e) . "<br>";
String Function
Chr, ord, strtolower, strtoupper, strlen, ltrim, rtrim trim, substr, strcmp,
strcasecmp, strops,strrpos, strstr, stristr, str_replace, strrev, echo, print
• echo():Outputs one or more strings
• print():Outputs one or more strings
• Chr(): Returns a character from a specified ASCII value
• ord():Returns the ASCII value of the first character of a string
• strtolower(): Converts a string to lowercase letters
• strtoupper():Converts a string to uppercase letters
• strlen():Returns the length of a string
• rtrim ():Removes whitespace or other characters from the right
side of a string
• ltrim():Removes whitespace or other characters from the left
side of a string
• trim():Removes whitespace or other characters from both sides of a string
String Function
Chr, ord, strtolower, strtoupper, strlen, ltrim, rtrim trim, substr, strcmp,
strcasecmp, strops,strrpos, strstr, stristr, str_replace, strrev, echo, print
– strcmp():Compares two strings (case-sensitive)
– strcasecmp():Compares two strings (case-insensitive)
– strpos():Returns the position of the first occurrence of a string inside
another string (case-sensitive)
– strrpos():Finds the position of the last occurrence of a string inside
another string (case-sensitive)
– strstr():Finds the first occurrence of a string inside another string
(case-sensitive)
– stristr():Finds the first occurrence of a string inside another string
(case-insensitive)
– str_replace():Replaces some characters in a string (case-sensitive)
– strrev():Reverses a string
Math Function
Abs, ceil, floor, round, fmod, min, max, pow, sqrt, rand
<?php
echo (abs(-7)."<br/>"); // 7
(integer)
echo (abs(7)."<br/>"); //7 (integer)
echo (abs(-7.2)."<br/>"); //7.2
(float/double)
?>
<?php
echo (ceil(3.3)."<br/>");// 4
echo (ceil(7.333)."<br/>");// 8
echo (ceil(-4.8)."<br/>");// -4
?>
<?php
echo (floor(3.3)."<br/>");// 3
echo (floor(7.333)."<br/>");//
7
echo (floor(-4.8)."<br/>");// -5
?>
<?php
echo (sqrt(16)."<br/>");// 4
echo (sqrt(25)."<br/>");// 5
echo (sqrt(7)."<br/>");//
2.6457513110646
?>
<?php
$num=pow(3, 2);
echo $num;
?>
echo "using round() function : ".(round(3.96754,2)); echo "Random number b/w 10-100:
".(rand(10,100));
$x = 5.7;
$y = 1.3;
echo "Your Given Nos is : x=5.7, y=1.3";
echo "<br>"."By using 'fmod()' function your
value is:".fmod($x, $y);
$num=min(4,14,3,5,14.2); $num=max(4,14,3,5,14.2);
User Define Function
argument function, default argument, variable function, return
function
function functionname(){
//code to be executed
}
<?php
function sayHello(){
echo "Hello PHP Function";
}
sayHello();//calling function
?>
function sayHello($name){
echo "Hello $name<br/>";
}
sayHello("Sonoo");
function sayHello($name,$age){
echo "Hello $name, you are $age years
old<br/>";
}
sayHello("Sonoo",27);
function adder(&$str2)
{
$str2 .= 'Call By Reference';
}
$str = 'Hello ';
adder($str);
echo $str;
function
sayHello($name="Sonoo"){
echo "Hello $name<br/>";
}
sayHello("Rajesh");
sayHello();
function cube($n){
return $n*$n*$n;
}
echo "Cube of 3 is:
".cube(3);
//RECURSIVE FUNCTIONS
<?php
function display($number) {
if($number<=5){
echo "$number <br/>";
display($number+1);
}
}
display(1);
Variable Length Argument Function:
func_num_args, func_get_arg, func_get_args
function combined() {
$num_arg = func_num_args();
echo "Number of arguments: " .$num_arg . "n";
}
combined('A', 'B', 'C');
<?php
function printValue($value) {
// Update value variable
$value = "The value is: " . $value;
// Print the value of the first argument
echo func_get_arg(0);
}
// Run function
printValue(123);
?>
<?php
function combined() {
$num_arg = func_num_args();
if($num_arg > 0) {
$arg_list = func_get_args();
for ($i = 0; $i < $num_arg; $i++) {
echo "Argument $i is: " . $arg_list[$i] . "n";
}
}
}
combined('A', 'B', 'C');
?>
Count, list, in_array, current, next, previous, end, each, sort, rsort,
asort,
arsort, array_merge, array_reverse
$a[0] = 1;
$a[1] = 3;
$a[2] = 5;
$result = count($a);
print($result);
$transport = array('foot', 'bike', 'car', 'plane');
$mode = current($transport);
print "$mode <br />";
$mode = next($transport);
print "$mode <br />";
$mode = current($transport);
print "$mode <br />";
$mode = prev($transport);
print "$mode <br />";
$mode = end($transport);
print "$mode <br />";
$mode = current($transport);
print "$mode <br />";
$transport = array('foot', 'bike',
'car', 'plane');
$key_value = each($transport);
print_r($key_value);
print "<br />";
$key_value = each($transport);
print_r($key_value);
print "<br />";
$key_value = each($transport);
print_r($key_value);
$fruit = array("mango","apple","banana");
list($a, $b, $c) = $fruit;
echo "I have several fruits, a $a, a $b, and
a $c.";
$input =
array("a"=>"banan
a","b"=>"mango","c
"=>"orange");
print_r(array_rever
se($input));
Count, list, in_array, current, next, previous, end, each, sort, rsort,
asort,
arsort, array_merge, array_reverse
$mobile_os = array("Mac", "android", "java",
"Linux");
if (in_array("java", $mobile_os)) {
echo "Got java";
}
<?php
$input = array("d"=>"lemon", "a"=>"orange", "b"=>"banana"
);
rsort($input);
print_r($input);
?>
<?php
$input = array("d"=>"lemon", "a"=>"orange",
"b"=>"banana" );
sort($input);
print_r($input);
?>
<?php
$fruits = array("d"=>"lemon", "a"=>"orange",
"b"=>"banana" );
arsort($fruits);
print_r($fruits);
?>
<?php
$fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana"
);
asort($fruits);
print_r($fruits);
?>
$input =
array("a"=>"Horse","b"=>"Cat","c"=>"Dog");
$input1 =
array("d"=>"Cow","a"=>"Cat","e"=>"elephant");
print_r(array_merge($input,$input1));
Miscellaneous Function
define, constant, include, require, header, die
<?php
define("GREETING","Hello you! How are you today?");
echo constant("GREETING");
?>
<?php
$site = "https://www.w3schools.com/";
fopen($site,"r")
or die("Unable to connect to $site");
?>
<?php
include("menu.html"); ?>
<?php
require("menu.html"); ?>
Both include and require are same. But if the file is missing or inclusion fails, include allows the
script to continue but require halts the script producing a fatal E_COMPILE_ERROR level error.
define() function to create a constant.
<?php
define("MESSAGE","Hello JavaTpoint PHP");
echo MESSAGE;
?>
define("MESSAGE","Hello JavaTpoint PHP",true);//not
case sensitive
The header() is a pre-defined network function of PHP, which sends a raw HTTP header to a client.
void header (string $header, boolean $replace = TRUE, int $http_response_code)
File handling Function:
fopen, fread, fwrite, fclose, file_exists, is_readable, is_writable, fgets, fgetc, file, file_get_contents,
filejutcontents, ftell, fseek, rewind, copy, unlink, rename, move upload file
<?php
$handle = fopen("c:folderfile.txt", "r");
?>
<?php
fclose($handle);
?>
<?php
$filename = "c:myfile.txt";
$handle = fopen($filename, "r");//open file in read
mode
$contents = fread($handle,
filesize($filename));//read file
echo $contents;//printing data of file
fclose($handle);//close file
?>
<?php
$fp = fopen('data.txt', 'w');//open file in write mode
fwrite($fp, 'hello ');
fwrite($fp, 'php file');
fclose($fp);
echo "File written successfully";
?>
fread(file_pointer, length)
echo fread($file_pointer, "7");
echo fgets($file);
if (file_exists($file_pointer)) {
echo "The file $file_pointer exists";
}
if (is_readable($myfile))
{
echo '$myfile is readable';
}
File handling Function:
fopen, fread, fwrite, fclose, file_exists, is_readable, is_writable, fgets, fgetc, file, file_get_contents,
filejutcontents, ftell, fseek, rewind, copy, unlink, rename, move upload file
$myfile = fopen("gfg.txt", "w");
echo fwrite($myfile, "Hello!");
fclose($myfile);
$myfile = fopen("gfg.txt", "r");
echo ftell($myfile);
fseek($myfile, "36");
echo ftell($myfile);
$myfile = fopen("gfg.txt", "r+");
fwrite($myfile, 'geeksforgeeks');
rewind($myfile);
fwrite($myfile, 'portal');
rewind($myfile);
echo fread($myfile, filesize("gfg.txt"));
fclose($myfile);
$srcfile = '/user01/Desktop/admin/gfg.txt';
$destfile = 'user01/Desktop/admin/geeksforgeeks.txt';
echo copy($srcfile, $destfilefile);
rename( $old_name, $new_name) ;
unlink('data.txt');
echo "File deleted successfully";
// file is opened using fopen() function
$my_file = fopen("gfg.txt", "rw");
// Prints a single character from the
// opened file pointer
echo fgetc($my_file);

More Related Content

What's hot

Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 
jQuery
jQueryjQuery
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
php
phpphp
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arrays
mussawir20
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
Muthuselvam RS
 
Php forms
Php formsPhp forms
Php forms
Anne Lee
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
Shweta A
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Java script
Java scriptJava script
Java script
Shyam Khant
 
The Functional Programming Toolkit (NDC Oslo 2019)
The Functional Programming Toolkit (NDC Oslo 2019)The Functional Programming Toolkit (NDC Oslo 2019)
The Functional Programming Toolkit (NDC Oslo 2019)
Scott Wlaschin
 
Php string function
Php string function Php string function
Php string function
Ravi Bhadauria
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
Taha Malampatti
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
Ahmed Swilam
 
Arrays in PHP
Arrays in PHPArrays in PHP
Form Handling using PHP
Form Handling using PHPForm Handling using PHP
Form Handling using PHP
Nisa Soomro
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
Manvendra Singh
 
Database Connectivity in PHP
Database Connectivity in PHPDatabase Connectivity in PHP
Database Connectivity in PHP
Taha Malampatti
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 

What's hot (20)

Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
jQuery
jQueryjQuery
jQuery
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 
php
phpphp
php
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arrays
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
Php forms
Php formsPhp forms
Php forms
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
Java script
Java scriptJava script
Java script
 
The Functional Programming Toolkit (NDC Oslo 2019)
The Functional Programming Toolkit (NDC Oslo 2019)The Functional Programming Toolkit (NDC Oslo 2019)
The Functional Programming Toolkit (NDC Oslo 2019)
 
Php string function
Php string function Php string function
Php string function
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
Form Handling using PHP
Form Handling using PHPForm Handling using PHP
Form Handling using PHP
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Database Connectivity in PHP
Database Connectivity in PHPDatabase Connectivity in PHP
Database Connectivity in PHP
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 

Similar to Php functions

Php & my sql
Php & my sqlPhp & my sql
Php & my sql
Norhisyam Dasuki
 
Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console component
Hugo Hamon
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
Pete McFarlane
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
David Golden
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
Vic Metcalfe
 
PHP record- with all programs and output
PHP record- with all programs and outputPHP record- with all programs and output
PHP record- with all programs and output
KavithaK23
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In Erlang
Sean Cribbs
 
PHP for Python Developers
PHP for Python DevelopersPHP for Python Developers
PHP for Python Developers
Carlos Vences
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
Hugo Hamon
 
R57shell
R57shellR57shell
R57shell
ady36
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
Jeff Carouth
 
Web Technology_10.ppt
Web Technology_10.pptWeb Technology_10.ppt
Web Technology_10.ppt
Aftabali702240
 
Smelling your code
Smelling your codeSmelling your code
Smelling your code
Raju Mazumder
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
Paulo Morgado
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
jhchabran
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
Sanketkumar Biswas
 
Refactor like a boss
Refactor like a bossRefactor like a boss
Refactor like a boss
gsterndale
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
Sérgio Rafael Siqueira
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Masahiro Nagano
 

Similar to Php functions (20)

Php & my sql
Php & my sqlPhp & my sql
Php & my sql
 
Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console component
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
 
PHP record- with all programs and output
PHP record- with all programs and outputPHP record- with all programs and output
PHP record- with all programs and output
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In Erlang
 
PHP for Python Developers
PHP for Python DevelopersPHP for Python Developers
PHP for Python Developers
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
R57shell
R57shellR57shell
R57shell
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
Web Technology_10.ppt
Web Technology_10.pptWeb Technology_10.ppt
Web Technology_10.ppt
 
Smelling your code
Smelling your codeSmelling your code
Smelling your code
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Refactor like a boss
Refactor like a bossRefactor like a boss
Refactor like a boss
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 

More from JIGAR MAKHIJA

Php gd library
Php gd libraryPhp gd library
Php gd library
JIGAR MAKHIJA
 
Db function
Db functionDb function
Db function
JIGAR MAKHIJA
 
C++ version 1
C++  version 1C++  version 1
C++ version 1
JIGAR MAKHIJA
 
C++ Version 2
C++  Version 2C++  Version 2
C++ Version 2
JIGAR MAKHIJA
 
SAP Ui5 content
SAP Ui5 contentSAP Ui5 content
SAP Ui5 content
JIGAR MAKHIJA
 
Solution doc
Solution docSolution doc
Solution doc
JIGAR MAKHIJA
 
Overview on Application protocols in Internet of Things
Overview on Application protocols in Internet of ThingsOverview on Application protocols in Internet of Things
Overview on Application protocols in Internet of Things
JIGAR MAKHIJA
 
125 green iot
125 green iot125 green iot
125 green iot
JIGAR MAKHIJA
 
Msp430 g2 with ble(Bluetooth Low Energy)
Msp430 g2 with ble(Bluetooth Low Energy)Msp430 g2 with ble(Bluetooth Low Energy)
Msp430 g2 with ble(Bluetooth Low Energy)
JIGAR MAKHIJA
 
Embedded system lab work
Embedded system lab workEmbedded system lab work
Embedded system lab work
JIGAR MAKHIJA
 
Presentation on iot- Internet of Things
Presentation on iot- Internet of ThingsPresentation on iot- Internet of Things
Presentation on iot- Internet of Things
JIGAR MAKHIJA
 
Oracle
OracleOracle
Learn Japanese -Basic kanji 120
Learn Japanese -Basic kanji 120Learn Japanese -Basic kanji 120
Learn Japanese -Basic kanji 120
JIGAR MAKHIJA
 
View Alignment Techniques
View Alignment TechniquesView Alignment Techniques
View Alignment Techniques
JIGAR MAKHIJA
 
Letters (complaints & invitations)
Letters (complaints & invitations)Letters (complaints & invitations)
Letters (complaints & invitations)
JIGAR MAKHIJA
 
Letter Writing invitation-letter
Letter Writing invitation-letterLetter Writing invitation-letter
Letter Writing invitation-letter
JIGAR MAKHIJA
 
Communication skills Revised PPT
Communication skills Revised PPTCommunication skills Revised PPT
Communication skills Revised PPT
JIGAR MAKHIJA
 
It tools &amp; technology
It tools &amp; technologyIt tools &amp; technology
It tools &amp; technology
JIGAR MAKHIJA
 
Communication skills
Communication skillsCommunication skills
Communication skills
JIGAR MAKHIJA
 
Use case modeling & analysis v 1
Use case modeling & analysis v 1Use case modeling & analysis v 1
Use case modeling & analysis v 1
JIGAR MAKHIJA
 

More from JIGAR MAKHIJA (20)

Php gd library
Php gd libraryPhp gd library
Php gd library
 
Db function
Db functionDb function
Db function
 
C++ version 1
C++  version 1C++  version 1
C++ version 1
 
C++ Version 2
C++  Version 2C++  Version 2
C++ Version 2
 
SAP Ui5 content
SAP Ui5 contentSAP Ui5 content
SAP Ui5 content
 
Solution doc
Solution docSolution doc
Solution doc
 
Overview on Application protocols in Internet of Things
Overview on Application protocols in Internet of ThingsOverview on Application protocols in Internet of Things
Overview on Application protocols in Internet of Things
 
125 green iot
125 green iot125 green iot
125 green iot
 
Msp430 g2 with ble(Bluetooth Low Energy)
Msp430 g2 with ble(Bluetooth Low Energy)Msp430 g2 with ble(Bluetooth Low Energy)
Msp430 g2 with ble(Bluetooth Low Energy)
 
Embedded system lab work
Embedded system lab workEmbedded system lab work
Embedded system lab work
 
Presentation on iot- Internet of Things
Presentation on iot- Internet of ThingsPresentation on iot- Internet of Things
Presentation on iot- Internet of Things
 
Oracle
OracleOracle
Oracle
 
Learn Japanese -Basic kanji 120
Learn Japanese -Basic kanji 120Learn Japanese -Basic kanji 120
Learn Japanese -Basic kanji 120
 
View Alignment Techniques
View Alignment TechniquesView Alignment Techniques
View Alignment Techniques
 
Letters (complaints & invitations)
Letters (complaints & invitations)Letters (complaints & invitations)
Letters (complaints & invitations)
 
Letter Writing invitation-letter
Letter Writing invitation-letterLetter Writing invitation-letter
Letter Writing invitation-letter
 
Communication skills Revised PPT
Communication skills Revised PPTCommunication skills Revised PPT
Communication skills Revised PPT
 
It tools &amp; technology
It tools &amp; technologyIt tools &amp; technology
It tools &amp; technology
 
Communication skills
Communication skillsCommunication skills
Communication skills
 
Use case modeling & analysis v 1
Use case modeling & analysis v 1Use case modeling & analysis v 1
Use case modeling & analysis v 1
 

Recently uploaded

ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
sayalidalavi006
 

Recently uploaded (20)

ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
 

Php functions

  • 2. Date Functions Date, getdate, setdate, Checkdate, time, mktime <?php $time = time(); print("Current Timestamp: ".$time); ?> <?php $bool = checkdate(12, 12, 2005); if($bool){ print("Given date is valid"); }else{ print("Given date is invalid"); } ?> DATE <?php $date = date("D M d Y"); print("Date: ".$date); ?> TIME <?php $timestamp = mktime(); print($timestamp); ?>
  • 3. Setting and Getting Dates <?php //Creating a date $date = new DateTime(); //Setting the date date_date_set($date, 2019, 07, 17); print("Date: ".date_format($date, "Y/m/d")); ?> <?php //Date string $date_string = "25-09-1989"; //Creating a DateTime object $date_time_Obj = date_create($date_string); print("Original Date: ".date_format($date_time_Obj, "Y/m/d")); print("n"); //Setting the date $date = date_date_set($date_time_Obj, 2015, 11, 25 ); print("Modified Date: ".date_format($date, "Y/m/d")); <?php //Creating a DateTime object $date_time_Obj = date_create("25-09-1989"); //formatting the date/time object $format = date_format($date_time_Obj, "y-d- m"); print("Date in yy-dd-mm format: ".$format); ?> <?php $info = getdate(); print_r($info); ?>
  • 4. Variable Function Gettype, settype, isset, unset, strval, floatval, intval, print_r $a = 3; echo gettype($a) . "<br>"; $b = 3.2; echo gettype($b) . "<br>"; $a = array("red", "green", "blue"); print_r($a); echo "<br>"; $b = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); print_r($b); <?php $a = "32"; // string settype($a, "integer"); // $a is now integer $b = 32; // integer settype($b, "string"); // $b is now string $c = true; // boolean settype($c, "integer"); // $c is now integer (1) ?> $a = 0; // True because $a is set if (isset($a)) { echo "Variable 'a' is set.<br>"; }
  • 5. Variable Function Gettype, settype, isset, unset, strval, floatval, intval, print_r $a = "Hello world!"; echo "The value of variable 'a' before unset: " . $a . "<br>"; unset($a); echo "The value of variable 'a' after unset: " . $a; ?> $b = 3.2; echo intval($b) . "<br>"; $c = "32.5"; echo intval($c) . "<br>"; $b = "1234.56789Hello"; echo floatval($b) . "<br>"; $c = "Hello1234.56789"; echo floatval($c) . "<br>"; $a = "1234.56789"; echo doubleval($a) . "<br>"; $b = "1234.56789Hello"; echo doubleval($b) . "<br>"; $d = "Hello1234.56789"; echo strval($d) . "<br>"; $e = 1234; echo strval($e) . "<br>";
  • 6. String Function Chr, ord, strtolower, strtoupper, strlen, ltrim, rtrim trim, substr, strcmp, strcasecmp, strops,strrpos, strstr, stristr, str_replace, strrev, echo, print • echo():Outputs one or more strings • print():Outputs one or more strings • Chr(): Returns a character from a specified ASCII value • ord():Returns the ASCII value of the first character of a string • strtolower(): Converts a string to lowercase letters • strtoupper():Converts a string to uppercase letters • strlen():Returns the length of a string • rtrim ():Removes whitespace or other characters from the right side of a string • ltrim():Removes whitespace or other characters from the left side of a string • trim():Removes whitespace or other characters from both sides of a string
  • 7. String Function Chr, ord, strtolower, strtoupper, strlen, ltrim, rtrim trim, substr, strcmp, strcasecmp, strops,strrpos, strstr, stristr, str_replace, strrev, echo, print – strcmp():Compares two strings (case-sensitive) – strcasecmp():Compares two strings (case-insensitive) – strpos():Returns the position of the first occurrence of a string inside another string (case-sensitive) – strrpos():Finds the position of the last occurrence of a string inside another string (case-sensitive) – strstr():Finds the first occurrence of a string inside another string (case-sensitive) – stristr():Finds the first occurrence of a string inside another string (case-insensitive) – str_replace():Replaces some characters in a string (case-sensitive) – strrev():Reverses a string
  • 8. Math Function Abs, ceil, floor, round, fmod, min, max, pow, sqrt, rand <?php echo (abs(-7)."<br/>"); // 7 (integer) echo (abs(7)."<br/>"); //7 (integer) echo (abs(-7.2)."<br/>"); //7.2 (float/double) ?> <?php echo (ceil(3.3)."<br/>");// 4 echo (ceil(7.333)."<br/>");// 8 echo (ceil(-4.8)."<br/>");// -4 ?> <?php echo (floor(3.3)."<br/>");// 3 echo (floor(7.333)."<br/>");// 7 echo (floor(-4.8)."<br/>");// -5 ?> <?php echo (sqrt(16)."<br/>");// 4 echo (sqrt(25)."<br/>");// 5 echo (sqrt(7)."<br/>");// 2.6457513110646 ?> <?php $num=pow(3, 2); echo $num; ?> echo "using round() function : ".(round(3.96754,2)); echo "Random number b/w 10-100: ".(rand(10,100)); $x = 5.7; $y = 1.3; echo "Your Given Nos is : x=5.7, y=1.3"; echo "<br>"."By using 'fmod()' function your value is:".fmod($x, $y); $num=min(4,14,3,5,14.2); $num=max(4,14,3,5,14.2);
  • 9. User Define Function argument function, default argument, variable function, return function function functionname(){ //code to be executed } <?php function sayHello(){ echo "Hello PHP Function"; } sayHello();//calling function ?> function sayHello($name){ echo "Hello $name<br/>"; } sayHello("Sonoo"); function sayHello($name,$age){ echo "Hello $name, you are $age years old<br/>"; } sayHello("Sonoo",27); function adder(&$str2) { $str2 .= 'Call By Reference'; } $str = 'Hello '; adder($str); echo $str; function sayHello($name="Sonoo"){ echo "Hello $name<br/>"; } sayHello("Rajesh"); sayHello(); function cube($n){ return $n*$n*$n; } echo "Cube of 3 is: ".cube(3); //RECURSIVE FUNCTIONS <?php function display($number) { if($number<=5){ echo "$number <br/>"; display($number+1); } } display(1);
  • 10. Variable Length Argument Function: func_num_args, func_get_arg, func_get_args function combined() { $num_arg = func_num_args(); echo "Number of arguments: " .$num_arg . "n"; } combined('A', 'B', 'C'); <?php function printValue($value) { // Update value variable $value = "The value is: " . $value; // Print the value of the first argument echo func_get_arg(0); } // Run function printValue(123); ?> <?php function combined() { $num_arg = func_num_args(); if($num_arg > 0) { $arg_list = func_get_args(); for ($i = 0; $i < $num_arg; $i++) { echo "Argument $i is: " . $arg_list[$i] . "n"; } } } combined('A', 'B', 'C'); ?>
  • 11. Count, list, in_array, current, next, previous, end, each, sort, rsort, asort, arsort, array_merge, array_reverse $a[0] = 1; $a[1] = 3; $a[2] = 5; $result = count($a); print($result); $transport = array('foot', 'bike', 'car', 'plane'); $mode = current($transport); print "$mode <br />"; $mode = next($transport); print "$mode <br />"; $mode = current($transport); print "$mode <br />"; $mode = prev($transport); print "$mode <br />"; $mode = end($transport); print "$mode <br />"; $mode = current($transport); print "$mode <br />"; $transport = array('foot', 'bike', 'car', 'plane'); $key_value = each($transport); print_r($key_value); print "<br />"; $key_value = each($transport); print_r($key_value); print "<br />"; $key_value = each($transport); print_r($key_value); $fruit = array("mango","apple","banana"); list($a, $b, $c) = $fruit; echo "I have several fruits, a $a, a $b, and a $c."; $input = array("a"=>"banan a","b"=>"mango","c "=>"orange"); print_r(array_rever se($input));
  • 12. Count, list, in_array, current, next, previous, end, each, sort, rsort, asort, arsort, array_merge, array_reverse $mobile_os = array("Mac", "android", "java", "Linux"); if (in_array("java", $mobile_os)) { echo "Got java"; } <?php $input = array("d"=>"lemon", "a"=>"orange", "b"=>"banana" ); rsort($input); print_r($input); ?> <?php $input = array("d"=>"lemon", "a"=>"orange", "b"=>"banana" ); sort($input); print_r($input); ?> <?php $fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana" ); arsort($fruits); print_r($fruits); ?> <?php $fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana" ); asort($fruits); print_r($fruits); ?> $input = array("a"=>"Horse","b"=>"Cat","c"=>"Dog"); $input1 = array("d"=>"Cow","a"=>"Cat","e"=>"elephant"); print_r(array_merge($input,$input1));
  • 13. Miscellaneous Function define, constant, include, require, header, die <?php define("GREETING","Hello you! How are you today?"); echo constant("GREETING"); ?> <?php $site = "https://www.w3schools.com/"; fopen($site,"r") or die("Unable to connect to $site"); ?> <?php include("menu.html"); ?> <?php require("menu.html"); ?> Both include and require are same. But if the file is missing or inclusion fails, include allows the script to continue but require halts the script producing a fatal E_COMPILE_ERROR level error. define() function to create a constant. <?php define("MESSAGE","Hello JavaTpoint PHP"); echo MESSAGE; ?> define("MESSAGE","Hello JavaTpoint PHP",true);//not case sensitive The header() is a pre-defined network function of PHP, which sends a raw HTTP header to a client. void header (string $header, boolean $replace = TRUE, int $http_response_code)
  • 14. File handling Function: fopen, fread, fwrite, fclose, file_exists, is_readable, is_writable, fgets, fgetc, file, file_get_contents, filejutcontents, ftell, fseek, rewind, copy, unlink, rename, move upload file <?php $handle = fopen("c:folderfile.txt", "r"); ?> <?php fclose($handle); ?> <?php $filename = "c:myfile.txt"; $handle = fopen($filename, "r");//open file in read mode $contents = fread($handle, filesize($filename));//read file echo $contents;//printing data of file fclose($handle);//close file ?> <?php $fp = fopen('data.txt', 'w');//open file in write mode fwrite($fp, 'hello '); fwrite($fp, 'php file'); fclose($fp); echo "File written successfully"; ?> fread(file_pointer, length) echo fread($file_pointer, "7"); echo fgets($file); if (file_exists($file_pointer)) { echo "The file $file_pointer exists"; } if (is_readable($myfile)) { echo '$myfile is readable'; }
  • 15. File handling Function: fopen, fread, fwrite, fclose, file_exists, is_readable, is_writable, fgets, fgetc, file, file_get_contents, filejutcontents, ftell, fseek, rewind, copy, unlink, rename, move upload file $myfile = fopen("gfg.txt", "w"); echo fwrite($myfile, "Hello!"); fclose($myfile); $myfile = fopen("gfg.txt", "r"); echo ftell($myfile); fseek($myfile, "36"); echo ftell($myfile); $myfile = fopen("gfg.txt", "r+"); fwrite($myfile, 'geeksforgeeks'); rewind($myfile); fwrite($myfile, 'portal'); rewind($myfile); echo fread($myfile, filesize("gfg.txt")); fclose($myfile); $srcfile = '/user01/Desktop/admin/gfg.txt'; $destfile = 'user01/Desktop/admin/geeksforgeeks.txt'; echo copy($srcfile, $destfilefile); rename( $old_name, $new_name) ; unlink('data.txt'); echo "File deleted successfully"; // file is opened using fopen() function $my_file = fopen("gfg.txt", "rw"); // Prints a single character from the // opened file pointer echo fgetc($my_file);