preg_match_all works when testing, but not in code

Solved

I've been trying to get preg_match_all to work, but I just can't seem to get it to work. I've run it through a regex tester and a preg_match_all tester. It works on those, but not on my code. I am using cURL to get the page. I've echoed the website, it loads. I've echoed it out using htmlentities wrapped in pre tags, it loads. When I try to print out the results, all I get is empty arrays. I've tested it on other sites and it works. Thanks.

The code: preg_match_all('/<tr>\n.*a href="(.*)">(.*)<\/a>.*\n.*">(.*)<\/a>.*\n.*">(.*)<\/a>.*\n.*<\/tr>/m', $in, $out);

Sample HTML:

        <tr>
                            <td><a href="city/miami">Miami, FL</a></td>
                            <td><a href="city/miami">Sep. 23-25</a></td>
                            <td><a href="city/miami">Miami Airport Convention Center</a></td>
                        </tr>

https://regex101.com/r/q3JQxk/1 - Proof that my regex works.

https://regex101.com/r/DQNgje/1 - Code quite similar, but it actually works.

https://www.functions-online.com/preg_match_all.html - Ran both regexes above and they work.

Edit: Wasn't formating links.

Posted Feb 17, 2017, 2:27 AM UTC

33
Loading comments…