sandy1028 Posted November 4, 2014 Share Posted November 4, 2014 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; } Quote Link to comment https://forums.phpfreaks.com/topic/292270-optimized-code/ Share on other sites More sharing options...
Ch0cu3r Posted November 4, 2014 Share Posted November 4, 2014 (edited) What are you validating a url or an email address? If it is an email address then dont bother with your own regex instead use filter_var with the FILTER_VALIDATE_EMAIL flag. Or use the FILTER_VALIDATE_URL flag for urls. Edited November 4, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/292270-optimized-code/#findComment-1495704 Share on other sites More sharing options...
sandy1028 Posted November 5, 2014 Author Share Posted November 5, 2014 Yes, trying to valid email id check in URL. Trying to check if email id is present in the URL Quote Link to comment https://forums.phpfreaks.com/topic/292270-optimized-code/#findComment-1495750 Share on other sites More sharing options...
Jacques1 Posted November 5, 2014 Share Posted November 5, 2014 (edited) 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 November 5, 2014 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/292270-optimized-code/#findComment-1495800 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.