php preg_match and ereg syntax difference

家住魔仙堡 提交于 2019-12-02 05:11:26
CSᵠ

For parsing HTML I'd suggest reading this question and choosing a built in PHP extension.

If for some reason you need or want to use RegEx to do it you should know that:

  • preg_match() is a greedy little bugger and it will try to eat your anything (.*) till it get's sick (meaning it hits recursion or backtracking limits). You change this with the U modifier1.

  • the engine expects to be fed a single line. You change this with the m or s modifiers1.

  • using your 'not a < character' ([^<]*) hack does a good job as it forces the engine to stop at the first < char, but will work only if the <div> doesn't contain other tags inside!

ref: 1PCRE Pattern Modifiers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!