so I have the code
function getTagContent($string, $tagname) {
$pattern = \"/<$tagname.*?>(.*)<\\/$tagname>/\";
preg_match($pattern, $string
The 'title' tag is not on the same line as its closing tag, so your preg_match doesn't find it.
In Perl, you can add a /s switch to make it slurp the whole input as though on one line: I forget whether preg_match will let you do so or not.
But this is just one of the reasons why parsing XML and variants with regexp is a bad idea.