I have a string that has two markers in it.
$str = 'The rest of the string is before [marker]content I want to keep[marker] and after the markers.';
I want to keep 'content I want to keep' and get rid of the rest of the string. How do I do this?
I have a string that has two markers in it.
$str = 'The rest of the string is before [marker]content I want to keep[marker] and after the markers.';
I want to keep 'content I want to keep' and get rid of the rest of the string. How do I do this?
You could use some fancy regex like the following:
if( preg_match('/(?<=\[marker])(.*)(?=\[marker])/i', $str, $match) ) {
echo "I found the following string:<br><br>" . $match[1];
} else {
echo "couldn't find it";
}
If there will just be the one occurrence:
$parts = explode('[marker]', $str);
if(count($parts) >= 2) {
echo $parts[1];
}