-3

I'd like to ignore what's inside a href element and make the function search with the rest of the pattern, I'd like it to be something like this:

preg_match('|<tr><td class="even"><a href="#">(.*?)</a></td>|', $content, $value)

Originally the href has /?tab=episode&seriesid=121361&seasonid=364731&id=3436411&amp;lid=16 but it's something I'd like the function to ignore.

EDITED: I'd like to match the 2 from <td class="even"><a href="/?tab=episode&seriesid=121361&seasonid=364731&id=3436411&amp;lid=16">2</a></td> but not just 1, i'll match more later and they have differents href values so i want a regex that means this href maybe variable. I don't know if i explained well, my english is not very good.

2 Answers2

0

If you use <a href="[^"]*"> it will match anything that isn't a " character.

Ideally you want to use a dom parser, See this post. SimpleXML with XPath is a good tool.

Scuzzy
  • 12,186
  • 1
  • 46
  • 46
-1

I believe you are searching for the following regex:

<tr><td class="even"><a href=".*">(.*)</a></td>

This will match all of these:

<tr><td class="even"><a href="/?tab=episode&seriesid=121361&seasonid=36ad31&id=3436411&amp;lid=16">2</a></td>
<tr><td class="even"><a href="/?tab=episode&seriesid=121361&seasonid=36aw31&id=3436411&amp;lid=16">1</a></td>
<tr><td class="even"><a href="/?tab=episode&adwadsonid=364731&id=3436411&amp;lid=16">Hallo</a></td>
<tr><td class="even"><a href="/?tab=episode&serwdadw1&seasonid=364731&id=3436411&amp;lid=16">Test</a></td>

I Also kept your (.*) as I am assuming you are using that group later.

If you want to search for a specific value in the a-tag content just replace (.*)with that.

SourceOverflow
  • 1,960
  • 1
  • 8
  • 22