0

I'm trying to extract to data between <table class="clubs"> .. </table> using this code:

preg_match('#\<table class\="clubs"\>(.*?)\</table\>#', $raw_data, $new_data);

My HTML markup:

but i get empty array! what's wrong? I believe everything is escaped correctly

4
  • 2
    Don't use a regex. Use a DOM parser instead. Commented Feb 23, 2014 at 17:37
  • I'd guess you need the whatever that option was to match across multiple lines. (Or, better yet, as @AmalMurali says, use a DOM parser) Commented Feb 23, 2014 at 17:38
  • The is one interesting post I read few hour back about html and regex stackoverflow.com/questions/1732348/… Commented Feb 23, 2014 at 17:40
  • 2
    @ElectricRouge: Please. That doesn't help the OP. I know it's cool and all, but that's not helpful. Stop linking to that. Commented Feb 23, 2014 at 17:45

1 Answer 1

3

The main problem is that . doesn't match newlines. You can fix it by using the s modifier to make . match newlines as well.

The second problem is that you're using //// while there should be only one /. You also have a lot of unnecessary escapes:

preg_match('#<table class="clubs">(.*?)</table>#s', $raw_data, $new_data);

Should work. regex101 demo

That said, you would be better off with a parser dedicated to parse HTML.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.