View Single Post
Old 01-08-2008, 11:36 AM   #1 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Big Grin Filter_var or RegEx?

I have been thinking most of the time about Filtering out the Variables or just a Regular Expression for matching different variables like for generally a Membership System with Email.
I want a comparison of Filter_var and RegEx when it comes to matching these vars.

Example of a Filter_Var:
PHP Code:
<?php
$filter1
=(filter_var('bob@example.com'FILTER_VALIDATE_EMAIL));
$filter2=(filter_var('example.com'FILTER_VALIDATE_URLFILTER_FLAG_SCHEME_REQUIRED));

  if(!
$filter) {
     echo 
'This email is not valid!';
} else {
  echo 
'Well pfft.. It is valid -_-';
}
?>
And thus the hard-coded ways:

PHP Code:
            $name "/^[-!#$%&'*+./0-9=?A-Z^_`{|}~]+";
// http://www.(example).com
            
$host "([-0-9A-Z]+.)+";
// This is extension or a TLD( Top Level Domain ) and it involves the Extension of the Host
            
$ext "([0-9A-Z]){2,4}$/i"

Which is more Powerful, and Effective? Obviously Filter_var is simpler in terms of matching vars.
Orc is offline  
Reply With Quote