Skip to main content

Posts

Showing posts with the label eregi_replace

More on POSIX regular expressions

• 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\&qu