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 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? 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); 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
Archived
This topic is now archived and is closed to further replies.