I need help on regex or preg_match because I am not that experienced yet with regards to those so here is my problem.
I need to get the value \"get me\" but I think
Since attribute values may contain a plain >
character, try this regular expression:
$pattern = '/<'.preg_quote($tagname, '/').'(?:[^"'>]*|"[^"]*"|\'[^\']*\')*>(.*?)<\/'.preg_quote($tagname, '/').'>/s';
But regular expressions are not suitable for parsing non-regular languages like HTML. You should better use a parser like SimpleXML or DOMDocument.
In your pattern, you simply want to match all text between the two tags. Thus, you could use for example a [\w\W]
to match all characters.
function getTextBetweenTags($string, $tagname) {
$pattern = "/<$tagname>([\w\W]*?)<\/$tagname>/";
preg_match($pattern, $string, $matches);
return $matches[1];
}