开发者

php preg_match two examples

I need to preg_match for

src="http://      "

where the blank space following // is the rest of the url ending with the ". My adapted doesn't seem to work:

preg_match('#src开发者_JS百科="(http://[^"]+)#', $data, $match); 

And I am also struggling to get text that starts with > and ends with EITHER a full stop . or an exclamation mark ! or a question mark ? I have no idea how to do this one. An example of the text I want to preg_match for is:

 blahblahblah>Hello world this is what I want.

I'm hoping a kind preg_match guru can tell me the answer and save me hours of headscratching.

Thanks for reading.


As for the URL:

preg_match('#src="(.*?)"#', $data, $match);

and for the second case, use />(.*?)(\.|!|\?)/


(.*?)" will match any character greedily up until the time it sees the end double quote


It seems that you want to parse a document or string which follows a HTML, DOM, XML or something similiar structure. Use XPath, and parse to the Tag and let it return the src Attribute, this will save much trouble and you can forget about regular expressions.

Example: CLICK ME

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜