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  never appears on output.

Thank you.
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
> $Pattern = "(http://)?([^[:space:]]+)([[:alnum:]\.,-_?/&=])";
> $Replace = "http://\\2\\3\"; target=\"_new\">\\2\\3";
> $Array["URL"] = eregi_replace($Pattern, $Replace, $Array["URL"]);
> 
> print ("Your submission--$Array[URL]--has been received!\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 = "http://\\2\\3\"; target=\"_new\">\\2\\3";
$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
> 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






First Name
Last Name 
URL 
Description





..
 //this is the script called 1201.php which receives the data from the form.



Using Regular Expressions


\n");
  }

$Pattern = "(http://)?([^[:space:]]+)([[:alnum:]\.,-_?/&=])";
$Replace = "http://\\2\\3\"; target=\"_new\">\\2\\3";
$Array["URL"] = eregi_replace($Pattern, $Replace, $Array["URL"]);

print ("Your submission--$Array[URL]--has been received!\n");

?>







---
[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
> 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
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
> 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




[PHP] eregi_replace() function in a script

2002-12-01 Thread Anthony Ritter
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 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






First Name
Last Name 
URL 
Description





..
 //this is the script called 1201.php which receives the data from the form.



Using Regular Expressions


\n");
  }

$Pattern = "(http://)?([^[:space:]]+)([[:alnum:]\.,-_?/&=])";
$Replace = "http://\\2\\3\"; target=\"_new\">\\2\\3";
$Array["URL"] = eregi_replace($Pattern, $Replace, $Array["URL"]);

print ("Your submission--$Array[URL]--has been received!\n");

?>



--





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