note 56859 added to function.preg-match
| From: | jsb17 at cornell dot edu | Date: | Sat, 17 Sep 2005 06:24:39 +0000 |
| Subject: | note 56859 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-95319@lists.php.net to get a copy of this message | ||
Regarding the 01-May-2005 06:02 post by berndt at www dot michael - berndt dot de
You claim "checks and validate an url with preg_match()" and then provide a link to your
web page that contains erroneous scripts, advertisements, and this example (as of Sept 17 2005):
<?php
function ValidateUrl($berndt){
return preg_match("#^([\w$-.+!*'()@:?=&/;]+)$#",$berndt)?1:0;
}
?>
1. This function in no way validates anything at all of any use whatsoever. This pregex as
concerns URLs is pure bogus.
2. The operators in your syntax <?php return (condition)?1:0 ?> should be spaced out, written
as <?php return(condition) ? 1 : 0 ?>. All operators in PHP should be spaced for
legibility, and interpretability. In PHP, two integers $a.$b could either be concatenated as
strings or interpreted as a decimal number by PHP. The behavior is unpredictable.
3. The syntax <?php return(condition)?1:0 ?> is redundant. Instead, simply write <?php
return(condition) ?>. The former doubles your execution time.
4. Functions carry overhead. If you want to reuse a pregex, or demonstrate it in the
documentation, make a variable. Writing a one line function is almost always absolutely pointless.
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56859
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56859&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56859&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56859&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56859&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56859&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+56859&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56859&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56859&report=yes
Search -- http://master.php.net/manage/user-notes.php