phppreg-matchtext-extraction

Regex used in preg_match() is not finding the expected URLs


I try to find a URL in a page.

The URL looks like this:

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

I have hidden the domain for the sake of posting.

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('~(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?


Solution

  • 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.