I need to grab text in between two tags, without a possible ending full stop, or if tags are not present, return no text at all.
The following should both return "Grab me":
(1) "text[tag]Grab me[/tag]text"
(2) "text[tag]Grab me.[/tag]text"
And this should return "":
(3) "text Grab me text"
Cases (1) and (2) work, while (3) returns: "text Grab me text".
function getTagText($str, $startTag, $endTag) {
return preg_replace("/.*".$startTag."(.*?)".$endTag.".*/s", '$1', $str);
}
$str .= getTagText($article['body'], "\[tag\]", "\.?+\[\/tag\]");
So, why does it return everything in $article['body'] when there is no "[tag]"?
Any input appreciated
regards
johan