-1

I have the string that is the html code and i want to get some tag from this html. Tag like below:

    <td width="33%" align="left" class="MID">
    <a href="ShowDOTCoByState.cfm?STATE=US&PHY_ST=IA">IOWA</a>
    </td>

How can i get tags using regex?

vmduan
  • 9
  • 1
  • 8

2 Answers2

1

better use this :

<?php
$html='<td width="33%" align="left" class="MID"><a href="ShowDOTCoByState.cfm?STATE=US&amp;PHY_ST=IA">IOWA</a></td>" id="blabah" >help</a>';
libxml_use_internal_errors(true);
$dom = new DOMDocument;
$dom->loadHTML($html);
echo $dom->getElementsByTagName('a')->item(0)->nodeValue;

this will get the value of the text written for link.

demo here : https://eval.in/202356

or if you are so fond on using regex :

<td.*?class="MID"[^>]*[\s\S]*?<\/td>

demo here : http://regex101.com/r/aS9pV1/1

aelor
  • 10,892
  • 3
  • 32
  • 48
0
(<td(?=.*?class="MID")[^>]*>(?:(?!<\/td>).)*<\/td>)

Try this.Add flags g and s.See demo.

http://regex101.com/r/mM8xF8/2

vks
  • 67,027
  • 10
  • 91
  • 124