Sunday, June 25, 2017

PHP string function with example...



Returns a string with backslashes in front of the specified characters
<?php 
$str = addcslashes("Hello World!","W");
echo($str); 
?>
Converts a string of ASCII characters to hexadecimal values
<?php 
$str = bin2hex("Hello World!");
echo($str); 
?>
Removes whitespace or other characters from the right end of a string
<?php
$str = "Hello World!";
echo $str . "<br>";
echo chop($str,"World!");
?>
Returns a character from a specified ASCII value
<?php
echo chr(52) . "<br>"; // Decimal value
echo chr(052) . "<br>"; // Octal value
echo chr(0x52) . "<br>"; // Hex value
?>
Splits a string into a series of smaller parts
<?php
$str = "Hello world!";
echo chunk_split($str,1,".");
?>
 
Splits a string into a series of smaller parts
<?php
$str = "Hello world! æøå";
echo $str . "<br>";
echo convert_cyr_string($str,'w','a'); 
?>

Converts a string from one Cyrillic character-set to another

<?php
$str = "Hello world! æøå";
echo $str . "<br>";
echo convert_cyr_string($str,'w','a'); 
?>
  
Decodes a uuencoded string
<?php
$str = ",2&5L;&\@=V]R;&0A `";
echo convert_uudecode($str);
?>
Encodes a string using the uuencode algorithm
<?php
$str = "Hello world!";
echo convert_uuencode($str);
?>



Returns information about characters used in a string
<?php
$str = "Hello World!";
echo count_chars($str,3);
?>
crc32()
Calculates a 32-bit CRC for a string
<?php
$str = crc32("Hello World!");
printf("%u\n",$str);
?>