simonp Posted February 7, 2009 Share Posted February 7, 2009 I have a form input as: $domain = $_POST['domain']; . . . but I need to check the string to see if it starts with 'www.' and if it does, remove it. How would I go about this? Cheers Simon Link to comment https://forums.phpfreaks.com/topic/144202-solved-remove-www-from-beginning-of-text-string/ Share on other sites More sharing options...
gaza165 Posted February 7, 2009 Share Posted February 7, 2009 i would use str_replace <?php $domain = "www.google.com"; $newdomain = str_replace("www.","",$domain); echo $newdomain; // will echo 'google.com' ?> Link to comment https://forums.phpfreaks.com/topic/144202-solved-remove-www-from-beginning-of-text-string/#findComment-756725 Share on other sites More sharing options...
simonp Posted February 7, 2009 Author Share Posted February 7, 2009 Thanks gaza165 Would that be ok if www. didn't exist in the input too? Simon Link to comment https://forums.phpfreaks.com/topic/144202-solved-remove-www-from-beginning-of-text-string/#findComment-756727 Share on other sites More sharing options...
gaza165 Posted February 7, 2009 Share Posted February 7, 2009 Thanks gaza165 Would that be ok if www. didn't exist in the input too? Simon not quite sure what you mean, what are you trying to extract out of the url?? http://www.mydomain.com are u just trying to get mydomain.com so if the url is http://mydomain.com Link to comment https://forums.phpfreaks.com/topic/144202-solved-remove-www-from-beginning-of-text-string/#findComment-756731 Share on other sites More sharing options...
gevans Posted February 7, 2009 Share Posted February 7, 2009 Yes it will only replace www. if it exsists. If it does not nothing happens to the URL. Link to comment https://forums.phpfreaks.com/topic/144202-solved-remove-www-from-beginning-of-text-string/#findComment-756732 Share on other sites More sharing options...
simonp Posted February 7, 2009 Author Share Posted February 7, 2009 Ah - thanks gaza165 and gevans. Works brilliantly Cheers Simon Link to comment https://forums.phpfreaks.com/topic/144202-solved-remove-www-from-beginning-of-text-string/#findComment-756734 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.