Ho bisogno di aiuto su regex o preg_match
perché non sono ancora così esperto riguardo a quelli così qui è il mio problema.PHP/regex: come ottenere il valore stringa del tag HTML?
Ho bisogno di ottenere il valore "get me" ma penso che la mia funzione abbia un errore. Il numero di tag html è dinamico. Può contenere molti tag html nidificati come un tag grassetto. Inoltre, il valore "get me" è dinamico.
<?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;
?>
possibile duplicato di [Potete fornire alcuni esempi del perché è difficile analizzare XML e HTML con una regex?] (Http: //stackoverflow.com/questions/701166/can-you-provide-some-examples-of-why-it-is-hard-to-parse-xml-and-html-with-a-rege) –
possibile duplicato di [RegEx match open tag tranne tag XHTML autonomi] (http://stackoverflow.com/questions/1732348/regex-match-open-ta gs-except-xhtml-self-contained-tags) –