RE: [PHP] eregi_replace() function in a script

2002-12-01 Thread John W. Holmes
 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?

Yes, that's correct. That piece of the pattern matches anything that's
not a space, one or more times. 

 I tried the script by putting a space before the URL and the PHP still
 processes the data with no error.

A space before everything is fine, as the pattern will match the
remainder of the string. If you put a ^ at the very beginning of the
pattern, that'll mean the beginning of the string must be followed by
(http), so then a space will cause the patter match to fail. 

---John Holmes...



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] eregi_replace() function in a script

2002-12-01 Thread Anthony Ritter
John W. Holmes:

 Yes, that's correct. That piece of the pattern matches anything that's
 not a space, one or more times.

  I tried the script by putting a space before the URL and the PHP still
  processes the data with no error.

 A space before everything is fine, as the pattern will match the
 remainder of the string. If you put a ^ at the very beginning of the
 pattern, that'll mean the beginning of the string must be followed by
 (http), so then a space will cause the patter match to fail.
...
Thanks for the reply John.

I still don't understand the explanation.

For instance, let's say I put _absolutely nothing_ in the URL textbox and
then hit submit - the PHP still processes _without_ an error.

It says:
Your submission -- -- has been received!

I would've thought the eregi_replace() function would've validated an entry
with no characters.

If you get a chance would you please try it out.

Thanks again for your time.
TR




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] eregi_replace() function in a script

2002-12-01 Thread John W. Holmes
 For instance, let's say I put _absolutely nothing_ in the URL textbox
and
 then hit submit - the PHP still processes _without_ an error.
 
 It says:
 Your submission -- -- has been received!
 
 I would've thought the eregi_replace() function would've validated an
 entry
 with no characters.

Well, whether it causes an error not depends on your code. That's just
the pattern you showed. It may not match anything, so nothing gets
replaced with eregi_replace() and hence no active link is created, but
it may not necessarily cause an error. 

Can you show me some of the code in context, with the pattern you showed
earlier and how eregi_replace is being used? Thanks.

---John Holmes...



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] eregi_replace() function in a script

2002-12-01 Thread Anthony Ritter
 Well, whether it causes an error not depends on your code. That's just
 the pattern you showed. It may not match anything, so nothing gets
 replaced with eregi_replace() and hence no active link is created, but
 it may not necessarily cause an error.

 Can you show me some of the code in context, with the pattern you showed
 earlier and how eregi_replace is being used? Thanks.

 ---John Holmes...
..

Sure.

BTW, here's a screenshot of the form and the result at:
www.gonefishingguideservice.com/php.htm

For a test, I put in a few spaces and then s  and then more spaces and
then o and then more spaces and then s and then I hit submit and the
script processed without an error.

So, I don't see where the eregi_replace() pattern matching is coming into
play.

Thank you.
TR
...
Here is Larry Ullman's PHP script on page 130 -131:

//this is the html form

HTML
HEAD
/HEAD
BODY
FORM METHOD=POST  ACTION=1201.php
First NameINPUT TYPE=TEXT NAME=Array[FirstName] SIZE=20BR
Last Name INPUT TYPE=TEXT NAME=Array[LastName] SIZE=40BR
URL INPUT TYPE=TEXT NAME=Array[URL] SIZE=60BR
DescriptionTEXTAREA NAME=Array[Description] ROWS=5
COLS=40/TEXTAREABR
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
TITLEUsing 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





---
[This E-mail scanned for viruses by gonefishingguideservice.com]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] eregi_replace() function in a script

2002-12-01 Thread John W. Holmes
 $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...



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] eregi_replace() function in a script

2002-12-01 Thread Anthony Ritter
Holmes:
That's just the pattern you showed. It may not match anything, so nothing
gets
 replaced with eregi_replace() and hence no active link is created, but
 it may not necessarily cause an error.
.

Right.

The pattern does not match anything in the input string of
$Array[URL]

so the A HREF=/A never appears on output.

Thank you.
TR





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php