$content='sldkfj;alsdkf<KNOWNRANDOMOPEN>TheRandomText</KNOWNRANDOMCLOSE>a;lsdkjf;alskdjf;lasdkf'; $patternopen='<KNOWNRANDOMOPEN>'; $patternclose='</KNOWNRANDOMCLOSE>'; echo $display; //Should only display "TheRandomText"
Im trying to grab info between two known patterns.
Any ideas?
Use a combination of [man]strpos[/man] and [man]substr[/man]. Or perhaps [man]preg_match[/man].
Two explodes got the job done.
Is this efficient?
$explode1=explode('<first_pattern>', $page_text); $explode2=explode('<sec_pattern>', $explode[1]); $new_name=$explode2["0"];
I'm not sure. You would need something to compare it to I guess and then run each method 1,000 times in a loop and see which is faster.
Just to offer a preg_match alternative:
preg_match('@<KNOWNRANDOMOPEN>(.*?)</KNOWNRANDOMOPEN>@si', $page_text, $matches); $new_name = (isset($matches[1]) ? $matches[1] : '');