stubarny1 Posted August 23, 2010 Share Posted August 23, 2010 Hello everyone, I'm looking to turn this string: $string = "jhdfgsdf984w5yisrek903_START_OF_WEBPAGE_http://www.google.com_END_OF_WEBPAGE" into this string: $string = "http://www.google.com" before the phrase "_START_OF_WEBPAGE_" could be any types of symbol or character. I've been trying to use regular expressions but can't seem to get them to work. Many thanks for your help. Stu Quote Link to comment https://forums.phpfreaks.com/topic/211554-removing-text-before-and-after-keyphrase/ Share on other sites More sharing options...
ZachMEdwards Posted August 23, 2010 Share Posted August 23, 2010 if (preg_match('/_START_OF_WEBPAGE_(.+)_END_OF_WEBPAGE/', $string, $matches)) { $string = $matches[1]; } else { $string = ""; } Yeah? Quote Link to comment https://forums.phpfreaks.com/topic/211554-removing-text-before-and-after-keyphrase/#findComment-1102909 Share on other sites More sharing options...
.josh Posted August 24, 2010 Share Posted August 24, 2010 $string = preg_replace('~/_START_OF_WEBPAGE_(.+?)_END_OF_WEBPAGE~','$1',$string); Quote Link to comment https://forums.phpfreaks.com/topic/211554-removing-text-before-and-after-keyphrase/#findComment-1103132 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.