xxxxxxxxxx
$char = "@@";
$char=substr($char,0,1);
echo strlen($char);//1
echo $char;//@
xxxxxxxxxx
<?php
// IF ONLY CHARACTER IN STRINGS
$str = "Hello PHP";
echo str_replace("PHP","",$str); // its remove PHP From string
//Output = Hello;
// IF NUMARIC OR CHARACTERS IN STRING AND YOU NEED ONLY STRING
$strInt = "124Peter56";
echo $words = preg_replace('/[0-9]+/', '', $strInt); // it remove integer from string
// Output = Peter;
// IF NUMARIC OR CHARACTERS IN STRING AND YOU NEED ONLY INTEGERS
$strInt = "124Peter56";
echo $res = preg_replace("/[^0-9]/", "", $strInt ); // It Remove all string
// Output = 12456
?>
xxxxxxxxxx
<?php
// Provides: <body text='black'>
$bodytag = str_replace("%body%", "black", "<body text='%body%'>");
// Provides: Hll Wrld f PHP
$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
$onlyconsonants = str_replace($vowels, "", "Hello World of PHP");
// Provides: You should eat pizza, beer, and ice cream every day
$phrase = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array("fruits", "vegetables", "fiber");
$yummy = array("pizza", "beer", "ice cream");
$newphrase = str_replace($healthy, $yummy, $phrase);
// Provides: 2
$str = str_replace("ll", "", "good golly miss molly!", $count);
echo $count;
?>
xxxxxxxxxx
$str = "Hello World";
// remove word "Hello"
$str = str_replace("Hello", "", $str);
// Output: " World"
xxxxxxxxxx
<?php
function trimm($str, $tr)
{
for ($i = 0; $i < strlen($str); $i++) {
if ($str[$i] == $tr) {
$str[$i] = " ";
}
}
return $str;
}
echo trimm("###sajjad#", "#");//sajjad