Regex - Greedyness - matching HTML tags, content and attributes

别来无恙 提交于 2019-12-02 08:58:40

We'll never reapeat it again : do not use regular expressions to work with HTML !


Instead, use DOMDocument::loadHTML.

It'll allow you to manipulate your HTML data using the DOM, which is much more powerful and easier : you'll be able to :

Really : take the time to learn DOM : it's a great investment !

You can specify it to be ungreedy using ?

/(<span lang="(.*?)">(.*?)<\/span>)/is

or make all expression ungreedy by default using PCRE_UNGREEDY modifier

/(<span lang="(.*)">(.*)<\/span>)/Uis

Just adding ? , I think

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