【发布时间】:2010-10-24 03:40:45
【问题描述】:
我需要关于正则表达式或preg_match 的帮助,因为我在这方面还没有那么丰富的经验,所以这是我的问题。
我需要获取值“get me”,但我认为我的函数有错误。 html标签的数量是动态的。它可以包含许多嵌套的 html 标记,例如粗体标记。此外,“get me”的价值是动态的。
<?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;
?>
【问题讨论】: