RE: [PHP] eregi_replace() function in a script
| From: | John W. Holmes | Date: | Mon, 02 Dec 2002 00:50:54 +0000 |
| Subject: | RE: [PHP] eregi_replace() function in a script | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-126654@lists.php.net to get a copy of this message | ||
> $Pattern = "(http://)?([^[:space:]]+)([[:alnum:]\.,-_?/&=])";
> $Replace = "<a href=\"http://\\2\\3\"
> target=\"_new\">\\2\\3</a>";
> $Array["URL"] = eregi_replace($Pattern, $Replace, $Array["URL"]);
>
> print ("Your submission--$Array[URL]--has been received!<BR>\n");
That does no checking or validation at all. It simply tries to replace a
pattern with another one. If the pattern isn't matched, then the
original string is returned unchanged.
If you want to validate the entry, then check to see if string has
changed at all.
$Pattern = "(http://)?([^[:space:]]+)([[:alnum:]\.,-_?/&=])";
$Replace = "<a href=\"http://\\2\\3\"
target=\"_new\">\\2\\3</a>";
$temp = $Array["URL"];
$Array["URL"] = eregi_replace($Pattern, $Replace, $Array["URL"]);
if(strcmp($temp,$Array["URL"])==0)
{ echo "You did not enter a good URL address."; }
---John Holmes...