开发者

preg_match php problem

i try to find a Link i a page

Link looks like this

https://pos.xxxxxxxxxx.de/xxxxxxxxxxxx/app?funnel=login_box&tid=2001004

i hide the domain :)

So there is my code:

preg_match('~(https://pos.xxxxxxxxxx.de/xxxxxxxxxx/app\?funnel=login_box&tid=\d+)~', $text, $ans);

nothing found...

i try this one

preg_match('~开发者_Go百科(https://pos.xxxxxxxxxx.de/xxxxxxxxxx/app\?funnel=login_box&tid=)~', $text, $ans);

try to find only the fixed part of the link...

stil nothing

so i try this one

preg_match('~(https://pos.xxxxxxxxxx.de/xxxxxxxxxx/app\?funnel=login_box)~', $text, $ans);

now i find some links, but why i can't find the whole link???


Probably in html source, & is expanded to &, try:

&(amp;)?

Just reminder - . means every char, so you should escape it, but it's not important here.


preg_match("/(https://[^=]+=[^=]+=[\d]+)/i",$text,$m);

if you have ' or " in the end of link, smth like this href="https://....."

you can use this one: preg_match("/\"(https://[^\"]+)\"/i",$text,$m);


$html = "http://www.scroogle.org
http://www.scroogle.org/
http://www.scroogle.org/index.html
http://www.scroogle.org/index.html?source=library
You can surf the internet anonymously at https://ssl.scroogle.org/cgi-bin/nbbwssl.cgi.";

preg_match_all('/\b((?P<protocol>https?|ftp):\/\/(?P<domain>[-A-Z0-9.]+)(?P<file>\/[-A-Z0-9+&@#\/%=~_|!:,.;]*)?(?P<parameters>\?[A-Z0-9+&@#\/%=~_|!:,.;]*)?)/i', $html, $urls, PREG_PATTERN_ORDER);
$urls = $urls[1][0];

Will match:

http://www.scroogle.org

http://www.scroogle.org/

http://www.scroogle.org/index.html

http://www.scroogle.org/index.html?source=library

You can surf the internet anonymously at https://ssl.scroogle.org/cgi-bin/nbbwssl.cgi.

To loop results you can use:

for ($i = 0; $i < count($urls[0]); $i++) {
    echo $urls[1][$i]."\n";
}

will output:

http://www.scroogle.org
http://www.scroogle.org/
http://www.scroogle.org/index.html
http://www.scroogle.org/index.html?source=library
https://ssl.scroogle.org/cgi-bin/nbbwssl.cgi

cheers, Lob

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜