Category Archives: Php Tutorial

PHP chunk_split Function


PHP chunk_split() Function : This Functions splits the string in series of smaller parts.


PHP chunk_split Function Syntax

chunk_split(string,length,end)

String : Required String input parameter.
Length : Optional , Number – The length of chunks. Default is 76.
End : Optional : String – Defines what to place at the end of each chunk. Default is \r\n

PHP chunk_split() function Example 1

$string = "Hello Tani!";
$chunk_split = chunk_split($string,3,'---');
echo $chunk_split;

Try it »

PHP chunk_split() function Example 2

$string = "Hello Tani!";
$chunk_split = chunk_split($string,1,'_');
echo $chunk_split;

Try it »

Output of the above Example will be as below:

PHP chunk_split Function

PHP chunk_split() Function

PHP chr Function


PHP chr function : is used to convert an ASCII number to character.

PHP chr Function Syntax

chr(ascii)

ascii : is ascii value to convert.

Return : Returns Characters

PHP chr() function Example 1

$chr = chr(42);
echo "my character value is : $chr";

Try it »

Note : ord() works as the reverse of the chr() function.

Output of the above Example :

PHP chr Function Example

PHP chr() Function

PHP chr() function Example 2

$chr = chr(100);
echo "my character value is : $chr";

Try it »

PHP chop Function


PHP chop Function : The Chop() function is used to remove the whitespaces or predefined character from right end of the string.

How to use PHP chop Function?

chop(string,charlist)

String: String to check.
charlist: Character List to be removed.
charlist : Following characters are removed if charlist is empty :

“\0” – NULL
“\t” – tab
“\n” – new line
“\x0B” – vertical tab
“\r” – carriage return
” ” – ordinary white space

function Example 2

$string = "Hey Buddy it's John";
$result = chop($string,"John");
echo $result;

Try it »

PHP chop Function

PHP chop Function Example

String With White Space At the End

PHP chop() function Example 2

$string = "Hey Buddy it's John ";
$result = chop($string);
echo $result;

Try it »

PHP bin2hex Function


PHP bin2hex Function :The string function bin2hex() converts the binary string to hexadecimal string. It accepts parameter as string and returns the hexadecimal.


Syntax for PHP bin2hex function :

bin2hex(string)

Returns : Hexadecimal String

PHP bin2hex Example 1

$string = "11111";
$result = bin2hex($string);
echo $result;

Try it »

bin2hex Function Example

PHP bin2hex Function Example

PHP bin2hex Example 2

$string = "Hello world!";
$result = bin2hex($string);
echo $result;

Try it »

PHP bin2hex Function Example

PHP bin2hex Example

PHP bin2hex Reverse

$string = "Hello world!";
$result1 = bin2hex($string);
echo $result1."
"; $result2 = pack("H*",$result1); echo $result2;

Try it »

PHP addslashes Function


PHP addslashes Function : The string function addslashes adds backslash(\) before each single quote(‘) , double quote(“) in string. Sometimes you need single quotes or double quotes with backslashes. Example (\”) or (\’)


How to use PHP addslashes Function Syntax


addslashes(string)

Input : String.

Retrun : String with backslash.

Single Quotes Example

$string = "Hey Buddy it's John";
$result = addslashes($string);
echo $result;

Try it »


We have a string “Hey Buddy it’s John” in which we will test the function addslashes. We want to add backslash before the “s” character ie “it\’s”. Which will produce the string with backslash as
“Hey Buddy it\’s John.”.
Output :

PHP addslashes Function

PHP addslashes Function

Double Quotes Example

$string = 'Hey Buddy it"s John';
$result = addslashes($string);
echo $result;

Try it »

Php addcslashes example


Php addcslashes example : The string function addcslashes adds backslash before the specified character.


Php addcslashes example Syntax

$string = addcslashes("Tutorialsplane is the Best.","B");
echo $string;

Try it »

We have a string “Tutorialsplane is the Best” in which we will test the function addcslashes. We want to add backslash before the “B” character ie before the “\B”. Which will produce the new string with backslash as
“Tutorialsplane is the \Best.”.
Output : The above example will add backslash before the word “Best” ie \Best. The Output of the above example will
be-

Php addcslashes example

Php addcslashes function example