housefire — 2011-10-23T15:58:26-04:00 — #1
Let's assume that one had a string variable something like:
$content = "garbage garbage garbage garbage <!-- MARKER --> gold gold gold gold <!-- / MARKER --> garbage garbage garbage garbage";
What would be the best way to be able to create a variable called $gold that contains only the "gold gold gold gold" content as marked by the opening and closing of the <!-- MARKER --> tag?
I'm having issues getting this small filtering task accomplished, any help would be much appreciated.
felgall — 2011-10-23T16:20:00-04:00 — #2
Use a regular expression
preg_match("/<!-- MARKER -->(.*?)<!--\ / MARKER -->/", $content, $matches);
$gold = $matches;
system — 2011-10-23T16:24:33-04:00 — #3
This demo function should do what you want.
The output is a string of the content between the markers.