开发者

regex link with php [duplicate]

开发者 https://www.devze.com 2023-04-04 15:01 出处:网络
This question already has answers here: 开发者_如何学JAVA Grabbing the href attribute of an A element
This question already has answers here: 开发者_如何学JAVA Grabbing the href attribute of an A element (10 answers) Closed 9 years ago.

i am trying to regex a difficult link

preg_match_all('/<a[^>]*href\s*=\s*(["\'])(.*?)\1[^>]*>\s+TEXTTOFIND+(.*?)\s*<\/a>/', '<a href="http://subdomain.BLABLABLA.net/de/cgi/g.fcgi/BLABLABLA/print?folder=inbox&amp;uid=U3RlcClzESBNZK9SDGsmQ05yIJTj7Eax&amp;CUSTOMERNO=124332225&amp;t=de1142311604.1315866430.20ba8551" style="margin-right: 10px;" title="&quot;BLABLABLA.net Registrierung&quot; &lt;register@gutefrage.net&gt;">"TEXTTOFIND.net R...
            </a>', $match);
        print_r($match);

BLABLABLA is only a test to hide the real page :)

all I want is to find the URL of link with "TEXTTOFIND"

but it doesn't work :(


You should be using a DOM parser to do this, not regular expressions. But if you want to do it the wrong way anyway, it looks like one of the reasons it isn't working is that you're trying to match:

... [^>]*>\s+TEXTTOFIND ...

But your test string is:

... >"TEXTTOFIND

Note the double quote " between the right angle bracket and your TEXTTOFIND string. The modifier from your regex, \s+, will not match this.


http://ua2.php.net/manual/en/function.preg-match-all.php

at first, try read docs, you miss 2nd parameter

at second, hello Alex :)

at 3rd \s+ you can change to . at some ... happens(sorry for my english)

0

精彩评论

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