PHP/regex: How to get the string value of HTML tag?

<?php
function getTextBetweenTags($string, $tagname) {
    $pattern = "/<$tagname ?.*>(.*)<\/$tagname>/";
    preg_match($pattern, $string, $matches);
    return $matches[1];
}

$str="<textformat leading="2"><p align="left"><font size="10">get me</font></p></textformat>";
$txt = getTextBetweenTags($str, "font");
echo $txt;
?>

That should do the trick

Leave a Comment