PHP String Manipulation 2


PHP STRING MANIPULATION part 2

chr ()

chr () function is used to translate the ASCII code. For example:
echo (chr (34); / / Will produce the sign "

ord () ord () function inverse of chr () is to convert from character to ASCII code for example:

echo (ord (")); / / Will generate 34

strlen ()
The function strlen () is used to determine the number of characters in a string. Example:
echo (strlen ("PHP Programming")); / / Will produce 15

ereg ()
ereg () function to check whether a word / phrase found in a sentence.

eregi ()
The function of eregi () equal to ereg () but in eregi () does not distinguish between large or small letters while the function ereg () distinguishes between uppercase and lowercase letters
Example:
<?
if (ereg ("php", "Programming PHP"))
{
  echo ("This one is not printed");
}
if (eregi ("php", "Programming PHP"))
{
  echo ("This one is printed");
}
?>
 
ereg_replace () and eregi_replace ()
ereg_replace () and eregi_replace () function to change the string that was found with the string replacement. Example:
<?
$str=”I am studying HTML”;
$replacement=”PHP”;
echo(eregi_replace(“html”,$replacement,$str));
// The output is ‘I am studying PHP’
?>

split () split () function to break a string and inserted into the array. For example:
<?
$str=”John,Jack,Ronn,Dave,Dunn”;
$separate=”,”;
$sen=split($separate,$str);
for($i=0;$i<count($sen);$i++)
{
  echo(“Name number-$i : $sen[i]”);
}
?>

0 comments:

Post a Comment