Category Archives: Php Tutorial

PHP html_entity_decode function


PHP html_entity_decode function : It converts the html entities to its applicable characters. This function decodes all html entities to its equivalent characters. We will explain this function with Syntax, Example And Demo .


Note : It Supports In PHP 4 and above versions.

PHP html_entity_decode function

Here is syntax for html_entity_decode function

Syntax: html_entity_decode function

html_entity_decode(string,flags,char-set);

Input(html_entity_decode) Parameters

Hers are parameters explained –

  • string: This is required input parameter which needs to be decoded.
  • flags: This is optional input parameter which handles single and double quotes. Here are following quote style-
    • ENT_COMPAT : This is default. Converts/Decodes only Double Quotes
    • ENT_QUOTES : This Decodes Both Single and Double Quotes.
    • ENT_NOQUOTES : Decodes neither Single nor Double Quotes.
  • char-set: This is optional parameter. This is basically used to decide which character set to use.
    • UTF-8 : This is Default ASCII Compatible Multi byte 8-bit Unicode.
    • ISO-8859-1 : Western European, Latin-1.
    • ISO-8859-15 : Western European, Latin-9
    • cp866: DOS-specific Cyrillic charset
    • cp1251 : Windows-specific Cyrillic charset.
    • cp1252 : Windows specific charset for Western European
    • KOI8-R : Russian.
    • BIG5 : Traditional Chinese, Specially used in Taiwan.
    • GB2312 : National standard character set.
    • BIG5-HKSCS : Traditional Chinese.
    • Shift_JIS SJIS, SJIS-win, cp932, 932 Japanese
    • EUC-JP :Japanese
    • MacRoman : Charset that was used by Mac OS.

Return(html_entity_decode) Parameters

Returns the decoded string.

PHP html_entity_decode function

Here is very basic example of html_entity_decode function –

html entity decode function Example:

PHP html_entity_decode function

Try It>>

If you run the above example it produce the following example as below-

PHP html_entity_decode function

PHP explode function


PHP explode function : It breaks the string into an array. It takes string as an input and returns the array.


Here is the PHP Syntax

explode(separator, string, limit)

separator : Separator the delimiter in string from where to break it in array such as break a string where whitespace found.
string : String As Input.
limit : Is optional which specifies how many elements to return.

There are following possible limits :
a. limit > 0 : Return an array with max possible limit.
b. limit = 0 : Return an array with one element all string parts will be in one element of array.
c. limit < 0 : Return the array except the last element of array.

PHP explode Function Example 1 : Limit = 2 (>0)

$str = "a b c d e";
$array = explode(" " , $str, 2);
print_r($array);

Try it »

Output Will Be :

PHP explode function

PHP explode() function

PHP explode Function Example 2 : Limit = 0

$str = "a b c d e";
$array = explode(" " , $str, 0);
print_r($array);

Try it »

Output of the above example will be :

PHP explode function

PHP explode() function

PHP explode Function Example 3 : Limit = -1 (<0)

$str = "a b c d e";
$array = explode(" " , $str, -1);
print_r($array);

Try it »

PHP explode function

PHP explode() function

PHP echo function


PHP echo function: Echo function is used to print the strings in php.


PHP echo function Syntax

echo strings

strings : Input Strings.
Return : Will print string.

Note 1 : Parenthesis are not required as “echo” is not function actually. It is construct. So you need not to use parenthesis with the echo.

Note 2 : Echo is faster than the print so we prefer to use echo instead of print.

PHP echo Function Example 1

$string = "Hi It's me Kelly!";
echo $string;

Try it »

As you see in the above example we have not used the parenthesis like this :echo($string) which is incorrect.

The below example shows the concatenation of the two strings.

PHP echo Function Example 2

$string1 = "Hi I am John !";

$string2 = "A Young Developer.";

echo $string1.' '.$string2;

Try it »

Output of the above example will be :

PHP echo Function Example

PHP echo() Function Example

Let us print an array using echo.

PHP echo Function Example 3

$array = array("0"=>"Tani","1"=>"The PHP Developer");
echo $array[0].' '.$array[1];

Try it »

PHP crypt Function


PHP crypt Function : It encrypts the string using the DES, Blowfish, or MD5 algorithms.


PHP crypt Function Syntax

crypt(str,salt)

String : Input String
Salt : An additional string to make more secure encryption.
Return : Hashed String.

PHP crypt Function Example

$passwoord = "mypassword";
$str = crypt($passwoord);
echo $str;

Try it »

Output of the above example will be :

PHP crypt Function

PHP crypt() Function

PHP crc32 Function


PHP crc32 Function : It creates the 32-Bit Cyclic redundancy checksum of a string.


PHP crc32 Function Syntax

crc(string)

String : Input String
Output : 32-Bit CRC Result.

PHP crc32 Function Example

$string = "Hello World !";
$str = crc32($string);
echo $str;

Try it »

Output of the above example will be :

PHP crc32 Function Example

PHP crc32 Function Example

PHP count_chars Function


PHP count_chars Function: It returns the characters and no of times used in the string.


How to use PHP count_chars Function?


count_chars(string,mode)

String : Input String
Mode : Defines the return mode. Following mode types are available.

0 – Array in key and value pair ASCII Value as key and number of occurrences as value.
1 – Array in key and value pair ASCII Value as key and number of occurrences as value only lists occurrences greater than zero.
2 – Array in key and value pair ASCII Value as key and number of occurrences as value only lists occurrences equal to zero.
3 – A string with all the different characters which have been used.
4 – A string with all characters which have not been used.

PHP count_chars Function Example 1

$string = "ABCA";
$s = count_chars($string,1);
print_r($s);

Try it »

In the Result below the ASCII value is key and The No of occurrence at value in array.
Output of the above example will be :

PHP count_chars Function

PHP count_chars() Function

PHP count_chars Function Example 1

$string = "ABCA";
$s = count_chars($string,3);
echo $s;

Try it »

PHP count_chars Function

PHP count_chars () Function

PHP convert_uudecode Function


PHP convert_uudecode Function : It is used to decode a string using the uudecode algorithm.


PHP convert_uudecode Function Syntax


convert_uudecode(string)

String : Input String
Output : Decoded String.

PHP convert_uudecode Function

$string = "-2&5L;&\@5V]R;&0@(0`` `";
$str = convert_uudecode($string);
echo $str;

Try it »

Output of the above example will be :

PHP convert_uudecode Function

PHP convert_uudecode() Function

PHP convert_uuencode Function


PHP convert_uuencode Function : It is used to encode a string using the uuencode algorithm.


PHP convert_uuencode Function Syntax


convert_uuencode(string)

String : Input String
Output : Encoded String.

PHP convert_uuencode Function

$string = "Hello World !";
$str = convert_uuencode($string);
echo $str;

Try it »

Output of the above example will be :

PHP convert_cyr_string Function

PHP convert_cyr_string() Function

PHP convert_cyr_string Function


PHP convert_cyr_string Function : Is Used to convert one character set to another character set.


PHP convert_cyr_string Function Syntax

convert_cyr_string(string, from, to)

Following charsets are available :

  • k – koi8-r
  • w – windows-1251
  • i – iso8859-5
  • a – x-cp866
  • d – x-cp866
  • m – x-mac-cyrillic

PHP convert_cyr_string Function

$string = "Hello World !";
$str = convert_cyr_string($string,w,a);
echo $str;

Try it »

Output of the above example will be :

PHP convert_cyr_string Function

PHP convert_cyr_string Function