开发者

php preg_match pattern for parsing tags

I want to know a good preg_match pattern in php for extracting data between tags.

For example :

 <page>
    <username>someone</username>
    <id>3020778</id>
    <text xml:space="preserve"> The qu开发者_开发问答ick brown fox. </text>
 </page>

This will give me the string "The quick brown fox".

I have tried using

preg_match('/<text(.*)?>(.*)?<\/text>/', $content, $match);

But it seems doesn't work on some other cases.

Does anyone have a better solution or pattern?

And does using simpleXML make it more faster than preg_match?


    $a = '<page>
<username>someone</username>
  <id>3020778</id>
  <text xml:space="preserve"> The quick brown fox. </text>
</page>';

preg_match_all("(\<.+\>(.+)\<\/.+\>)U",$a, $r);    
?><pre><? print_r($r);?></pre><?
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜