cetinakat
cetinakat

Reputation: 45

How to get strings with Regex

I want to get strings between td's but one of the td has not close tag. How can I get from this tag with other string.

<tr>
<td class="exclass">Text 0
<td class="exclass"><a href="exampleUrl">Text 1</a></td>
<td class="exclass"><a href="exampleUrl">Text 2</a></td>
<td class="exclass3" >Text</td >
<td class="exclass"> Text </td>
<td class="exclass3">Text</td>
<td class="exclass">Text</td>
<td class="exclass">Text</td><td class="exclass">Text</td>
<td class="exclass2">Text</td>
<td class="exclass">Text</td>
<td class="exclass" width="20"><a href="exampleUrl" rel="nofollow"><img src="exampleSrc"></a></td>
</tr>

As you can see below code, I want to get Text 0 and the other strings with PHP. So far, I tried to:

<td.+?>([\w\W]*?)<\/td.+?|<td

Upvotes: 0

Views: 36

Answers (1)

stars_point
stars_point

Reputation: 106

I assume because one of the td doesn't have close tag, that's why you can't use the DOM parser.

Here is my regex solution

(?<=>)([\s\w\n]+)(?=<)

https://regex101.com/r/BRaJAu/1

Upvotes: 1

Related Questions