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
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'])?

Edited by Jacques1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.