Advanced Web Development Using
chr() Function
• The chr() function returns a character from
the specified ASCII value.
• The ASCII value can be specified in decimal,
octal, or hex values. Octal values are defined
by a leading 0, while hex values are defined by
a leading 0x.
Example
• <?php
echo chr(52) . "<br>"; // Decimal value
echo chr(052) . "<br>"; // Octal value
echo chr(0x52) . "<br>"; // Hex value
?>
ord() Function
• The ord() function returns the ASCII value of
the first character of a string.
Example
• <?php
echo ord("h")."<br>";
echo ord("hello")."<br>";
?>
strtolower() Function
• The strtolower() function converts a string to
lowercase.
Example
• <?php
echo strtolower("Hello WORLD.");
?>
strtoupper() Function
• The strtoupper() function converts a string to
uppercase.
Example
• <?php
echo strtoupper("Hello WORLD!");
?>
strlen() Function
• The strlen() function returns the length of a
string.
Example
• <?php
echo strlen("Hello");
?>
ltrim() Function
• The ltrim() function removes whitespace or
other predefined characters from the left side
of a string.
Example
• <?php
$str = "Hello World!";
echo $str . "<br>";
echo ltrim($str,"Hello");
?>
rtrim() Function
• The rtrim() function removes whitespace or
other predefined characters from the right
side of a string.
Example
• <?php
$str = "Hello World!";
echo $str . "<br>";
echo rtrim($str,"World!");
?>
trim() Function
• The trim() function removes whitespace and
other predefined characters from both sides
of a string.
Example
• <?php
$str = "Hello World!";
echo $str . "<br>";
echo trim($str,"Hed!");
?>
substr() Function
• The substr() function returns a part of a string.
Example
• <?php
echo substr("Hello world",6,2);
?>
– Syntax :
• substr(string,start,length)
strcmp() Function
• The strcmp() function compares two strings.
• This function returns:
0 - if the two strings are equal;
<0 - if string1 is less than string2;
>0 - if string1 is greater than string2.
Example
• <?php
echo strcmp("Hello world!","Hello world!");
?>
strcasecmp() Function
• The strcasecmp() function compares two strings.
Tip: The strcasecmp() function is binary-safe and
case-insensitive.
• This function returns:
0 - if the two strings are equal;
<0 - if string1 is less than string2;
>0 - if string1 is greater than string2.
Example
• <?php
echo strcasecmp("Hello world!","HELLO
WORLD!");
?>
strpos() Function
• The strpos() function finds the position of the
first occurrence of a string inside another
string.
Example
• <?php
echo strpos("I like php too!","php");
?>
strrpos() Function
• The strrpos() function finds the position of the
last occurrence of a string inside another
string.
Example
• <?php
echo strrpos("I love php, I love php
too!","php");
?>
strstr() Function
• The strstr() function searches for the first
occurrence of a string inside another string &
returns string from that occurance.
Example
• <?php
echo strstr("Hello world!","world");
?>
stristr() Function
• The stristr() function searches for the first
occurrence of a string inside another string &
returns string from that occurance without
concerning it’s case.
Example
• <?php
echo stristr("Hello world!","WORLD");
?>
str_replace() Function
• The str_replace() function replaces some
characters with some other characters in a
string.
Example
• <?php
echo str_replace("world","Peter","Hello
world!");
?>
strrev() Function
• The strrev() function reverses a string.
Example
• <?php
echo strrev("Hello World!");
?>
echo() Function
• The echo() function outputs one or more
strings.
• Note: The echo() function is not actually a
function, so you are not required to use
parentheses with it. However, if you want to
pass more than one parameter to echo(),
using parentheses will generate a parse error.
Example
• <?php
echo "Hello world!";
?>
print() Function
• The print() function outputs one or more
strings.
Example
• <?php
print ("Hello world!“);
?>