brown2005 Posted February 6, 2013 Share Posted February 6, 2013 function url_strip($url){ return preg_replace('#^https?://www.#', '', $url); } I currently have the above function witch strips say http://www.thiswebsite.co.uk into thiswebsite.co.uk what I want to do is add $remove = array('https://www.','http://www.','https://','http://','www.'); this into the function, I have tried function url_strip($url){ $remove = array('https://www.','http://www.','https://','http://','www.'); foreach($remove as $key => $val){ $array[$key] = preg_replace(''.$val.'','', $url); } return $url; } Quote Link to comment https://forums.phpfreaks.com/topic/274111-function-to-strip-a-website-url/ Share on other sites More sharing options...
Christian F. Posted February 6, 2013 Share Posted February 6, 2013 If you change preg_replace () to str_replace () your code should work. Reason why it's not working now, is because the $remove array doesn't contain valid Regular Expressions. Just plain strings. Quote Link to comment https://forums.phpfreaks.com/topic/274111-function-to-strip-a-website-url/#findComment-1410466 Share on other sites More sharing options...
JonnoTheDev Posted February 6, 2013 Share Posted February 6, 2013 Even simpler <?php function url_strip($url) { $parts = parse_url($url); return str_replace('www.', '', $parts['host']); } echo url_strip('http://www.thiswebsite.co.uk'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/274111-function-to-strip-a-website-url/#findComment-1410484 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.