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; } 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 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. 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 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 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.