Hi,
The following appliaction for the following html form and php script was
taken from Larry Ullman's book on PHP on page 130 - 131.
What it does is this:
1. the user is presented with a form with a few textboxes and a textarea
box.
2. the user fills in the boxes with a URL and a descripttion of the URL and
submits it.
3. the PHP takes the string which has three groupings and parses it uses the
eregi_replace() function.
4. The end result is that the URL input from the user becomes a active <A
HREF>link.
The script works fine but I have a question with the following line:
$Pattern="(http://)([^[:space:]]+) ([[:alnum:]\.,-?/&=])"; // The variable
$Pattern is declared with three groupings.
My question:
If the user inadvertantly inputs a *space* _after_ the http:// grouping and
_before_ the www. grouping my understanding is that would not be valid from
the $Pattern match due to:
................
([^[:space:]]+)
..................
Correct?
I tried the script by putting a space before the URL and the PHP still
processes the data with no error.
Please advise.
Thank you.
Tony Ritter
//this is the html form
<HTML>
<HEAD>
</HEAD>
<BODY>
<FORM METHOD=POST ACTION="1201.php">
First Name<INPUT TYPE=TEXT NAME="Array[FirstName]" SIZE=20><BR>
Last Name <INPUT TYPE=TEXT NAME="Array[LastName]" SIZE=40><BR>
URL <INPUT TYPE=TEXT NAME="Array[URL]" SIZE=60><BR>
Description<TEXTAREA NAME="Array[Description]" ROWS=5
COLS=40></TEXTAREA><BR>
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
</FORM>
</BODY>
</HTML>
..................
//this is the script called 1201.php which receives the data from the form.
<HTML>
<HEAD>
<TITLE>Using Regular Expressions</TITLE>
</HEAD>
<BODY>
<?php
if (($Array["FirstName"]) AND ($Array["LastName"]))
{
$Array["Name"] = $Array["FirstName"] . " " . $Array["LastName"];
}
else
{print ("Please enter your first and last names.<BR>\n");
}
$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");
?>
</BODY>
</HTML>
--
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php