<?php $string = 'some text <tag:cate name="a">a<tag:cate name="b">b<tag:cate>c</tag:cate>d</tag:cate>e</tag:cate> more text'; preg_match("/<tag:cate(?: name=\"\w+\")?>(?>\w+|(?R))*<\/tag:cate>/",$string,$matches) && print_r($matches);
$string = 'some text <tag:cate name="a"><div></div><tag:cate name="b"><div></div><tag:cate>c</tag:cate>d</tag:cate>e</tag:cate> more text'; if(preg_match('#<tag:cate name="\w+">(.*)</tag:cate>#i',$string,$matches)) { echo "<pre>"; print_r($matches); echo "</pre>"; }
不好意思,刚刚问题说漏了一点,<tag:cate name="a"></tag:cate>之间不一定是问题,有可能是HTML标签,比如$string = 'some text <tag:cate name="a"><div>a</div><tag:cate name="b"><div></div><tag:cate>c</tag:cate>d</tag:cate>e</tag:cate> more text';
<?php $string = 'some text <tag:cate name="a"><div>a</div><tag:cate name="b"><div></div><tag:cate>c</tag:cate>d</tag:cate>e</tag:cate> more text'; preg_match("/<tag:cate(?: name=\"\w+\")?>(?>(?:<\/?\w+>)|\w+|(?R))*<\/tag:cate>/",$string,$matches) && print_r($matches);
各位大虾,不好意思,我的问题发错了一点 $string = 'some text <tag:cate name="a"><div></div><tag:cate name="b"><div></div><tag:cate>c</tag:cate>d<tag:cate>e</tag:cate> more text';我想匹配为 <tag:cate name="a"><div></div><tag:cate name="b"><div></div><tag:cate>c</tag:cate> <tag:cate>e</tag:cate>string中的<tag:cate></tag:cate>个数不定,大虾们拜托再帮帮忙,非常感谢
$string = 'some text <tag:cate name="a">a<tag:cate name="b">b<tag:cate>c</tag:cate>d</tag:cate>e</tag:cate> more text';
preg_match("/<tag:cate(?: name=\"\w+\")?>(?>\w+|(?R))*<\/tag:cate>/",$string,$matches) &&
print_r($matches);
if(preg_match('#<tag:cate name="\w+">(.*)</tag:cate>#i',$string,$matches))
{
echo "<pre>"; print_r($matches); echo "</pre>";
}
不好意思,刚刚问题说漏了一点,<tag:cate name="a"></tag:cate>之间不一定是问题,有可能是HTML标签,比如$string = 'some text <tag:cate name="a"><div>a</div><tag:cate name="b"><div></div><tag:cate>c</tag:cate>d</tag:cate>e</tag:cate> more text';
$string = 'some text <tag:cate name="a"><div>a</div><tag:cate name="b"><div></div><tag:cate>c</tag:cate>d</tag:cate>e</tag:cate> more text';
preg_match("/<tag:cate(?: name=\"\w+\")?>(?>(?:<\/?\w+>)|\w+|(?R))*<\/tag:cate>/",$string,$matches) &&
print_r($matches);
$string = 'some text <tag:cate name="a"><div></div><tag:cate name="b"><div></div><tag:cate>c</tag:cate>d<tag:cate>e</tag:cate> more text';我想匹配为
<tag:cate name="a"><div></div><tag:cate name="b"><div></div><tag:cate>c</tag:cate>
<tag:cate>e</tag:cate>string中的<tag:cate></tag:cate>个数不定,大虾们拜托再帮帮忙,非常感谢