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

Php.ppt
Php.pptPhp.ppt
Php.ppt
Nidhi mishra
 
4.2 PHP Function
4.2 PHP Function4.2 PHP Function
4.2 PHP Function
Jalpesh Vasa
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
Ahmed Swilam
 
Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
Maruf Abdullah (Rion)
 
PHP Loops and PHP Forms
PHP  Loops and PHP FormsPHP  Loops and PHP Forms
PHP Loops and PHP Forms
M.Zalmai Rahmani
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
CPD INDIA
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
Henry Osborne
 
PHP
PHPPHP
JavaScript Arrays
JavaScript Arrays JavaScript Arrays
JavaScript Arrays
Reem Alattas
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
Vibrant Technologies & Computers
 
Working with arrays in php
Working with arrays in phpWorking with arrays in php
Working with arrays in php
Kamal Acharya
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
ShahDhruv21
 
JAVA PROGRAMMING - The Collections Framework
JAVA PROGRAMMING - The Collections Framework JAVA PROGRAMMING - The Collections Framework
JAVA PROGRAMMING - The Collections Framework
Jyothishmathi Institute of Technology and Science Karimnagar
 
Php mysql
Php mysqlPhp mysql

What's hot (20)

Php.ppt
Php.pptPhp.ppt
Php.ppt
 
4.2 PHP Function
4.2 PHP Function4.2 PHP Function
4.2 PHP Function
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
 
PHP Loops and PHP Forms
PHP  Loops and PHP FormsPHP  Loops and PHP Forms
PHP Loops and PHP Forms
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
PHP
PHPPHP
PHP
 
Operators in PHP
Operators in PHPOperators in PHP
Operators in PHP
 
JavaScript Arrays
JavaScript Arrays JavaScript Arrays
JavaScript Arrays
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
 
Working with arrays in php
Working with arrays in phpWorking with arrays in php
Working with arrays in php
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
JAVA PROGRAMMING - The Collections Framework
JAVA PROGRAMMING - The Collections Framework JAVA PROGRAMMING - The Collections Framework
JAVA PROGRAMMING - The Collections Framework
 
Php mysql
Php mysqlPhp mysql
Php mysql
 

Similar to Php functions

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 2011Masahiro 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
 
Php pattern matching
Php pattern matchingPhp pattern matching
Php pattern matching
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
 

More from JIGAR MAKHIJA (20)

Php gd library
Php gd libraryPhp gd library
Php gd library
 
Php pattern matching
Php pattern matchingPhp pattern matching
Php pattern matching
 
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
 

Recently uploaded

The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 

Recently uploaded (20)

The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 

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);