note 56859 deleted from function.preg-match by mazzanet
| From: | mazzanet@php.net | Date: | Sat, 17 Sep 2005 10:53:05 +0000 |
| Subject: | note 56859 deleted from function.preg-match by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-95323@lists.php.net to get a copy of this message | ||
Note Submitter: jsb17 at cornell dot edu
----
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.