0
    preg_match_all('|<tr>(.*?)</tr>|', '<table>
<tr>
<td>oo</td>
</tr>
<tr>
<td>ddd</td>
</tr>
</table>', $matches, PREG_PATTERN_ORDER);

why this doesn't show any results. I want to get second match $matches[1][2]

goni
  • 53
  • 2
  • 6
  • 2
    Advice: don't use regex to parse HTML. Use a genuine HTML parser instead. – lonesomeday Jun 04 '11 at 12:11
  • I second this advice, however what do you mean by Genuine HTML parser? Any good way to do that in PHP? – Alex Jun 04 '11 at 12:18
  • 1
    I see you only have one group, `(.*?)`. What do you expect to find in `$matches[1][2]`? – rid Jun 04 '11 at 12:22
  • 1
    @AlexanderMP http://simplehtmldom.sourceforge.net/ – Matt Jun 04 '11 at 12:30
  • Note: matches counting starts from 0. So, if you need second match, you would use $matches[1][1]. –  Jun 04 '11 at 12:32
  • 1
    Do not use simplehtmldom if you can avoid it: there are way faster methods: see http://stackoverflow.com/questions/3577641/best-methods-to-parse-html-with-php/3577662#3577662 – Wrikken Jun 04 '11 at 12:59
  • simplehtmldom use same codes as regex and preg_match I dont see any difference with my code below – goni Jun 04 '11 at 16:30

1 Answers1

4

You need to use the s pattern modifier

preg_match_all('|<tr>(.*?)</tr>|s', ...

user775263
  • 246
  • 1
  • 1