Jump to content

Optimized code


sandy1028

Recommended Posts

          

Please tell me which is the optimized code and which works faster. Let me know f there is any other way for the faster approach

          $page_url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
                    if (preg_match('/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/si', $page_url)){
                        return false;
                    }
 
      OR
             $url_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
                    $email_reg_ex = "/[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})/i";
                    $render_if_email_id_not_present =  preg_match($email_reg_ex, $url_link);


                    if (!empty($render_if_email_id_not_present)){
                       return false;
                    }
Link to comment
https://forums.phpfreaks.com/topic/292270-optimized-code/
Share on other sites

The whole approach doesn't make a lot of sense.

 

The hostname obviously cannot contain an e-mail address, so why would you waste time checking "http://".$_SERVER['HTTP_HOST']? I'm also fairly sure that you don't have e-mail addresses within the path or the URL fragment, so again, why check them? 

 

What is the concrete goal? Check the presence of a specific URL parameter? Then why not simple check isset($_GET['the_name_of_your_parameter'])?

Link to comment
https://forums.phpfreaks.com/topic/292270-optimized-code/#findComment-1495800
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.