PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
if (preg_match ("/php/i", "PHP is the web scripting language and php is my 1st choice.")) {
print "A match was found.";
} else {
print "A match was not found.";
}
in the above example i can check the string now how can i padd "_" on both sides of all "php"'s
$string= "Alien Is my friend, and I like mango.";
$string = str_replace('i', '_i_', $string);
$string = str_replace('I', '_I_', $string);
echo $string;
$string= "Alien Is my friend, and I like mango.";
$string = str_replace('i', '_i_', $string);
$string = str_replace('I', '_I_', $string);
echo $string;
is there any better solution than the above one using reguller expression.....
$string= "Alien Is my friend, and I like mango.";
$string = str_replace('i', '_i_', $string);
$string = str_replace('I', '_I_', $string);
echo $string;
is there any better solution than the above one using reguller expression.....
thanx.
For a simple replacement like that it's actually faster (by quite a lot) to use a couple of str_replace()s than one regular expression.