开发者

Get content between code tag return in array

I want to get the content between a code tag in a html document. I tried开发者_JAVA百科 forming it in preg_match... Could anybody help me..


If you want to use preg_match, do:

preg_match("/<code>(.+?)<\/code>/is", $content, $matches);

Then access it with

$matches[1]

Though in general, you are going to find more use and better performance with a HTML Parser, which is the preferred method to Regular Expressions.


It's easier if you use phpQuery or QueryPath which allow:

print qp($html)->find("code")->text();
// looks for the <code> tag and prints the text content

If you want to try regular expressions for this, check out some of the tools listed in https://stackoverflow.com/questions/89718/is-there-anything-like-regexbuddy-in-the-open-source-world for help.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜