• ereg_replace()-
This function is equivalent to ereg() in its case-sensitive searching capabilities;
however, it adds the ability to replace the characters it is searching for with new characters instead of
just simply locating them. If the search pattern is not found, the string it searched against is
unchanged.
<?php
$url = "MySQL http://www.mysql.com";
print ereg_replace("http://([a-zA-Z0-9./-]+)$",
"<a href=\"\\0\">\\0</a>", $url);
?>
The script above would change the text "MySQL http://www.mysql.com" to "MySQL <a
href="http://www.mysql.com">http://www.mysql.com</a>". This change would allow the http
reference to be replaced with the HTML code required to create a web link. The three components of
this function include the pattern to search for ("http://([a-zA-Z0-9./-]+)$"), the replacement string ("<a
href=\"\\0\">\\0</a>") and then finally the variable that is going to be searched and replaced. The \\0
tells the ereg_replace() function to repeat the complete matched pattern (in this case
http://www.mysql.com).
• eregi_replace -
This function is identical to ereg_replace(), except that it is case insensitive when
searching.
Comments
Post a Comment