<tr id='ieconn3' >
<td><table width='100%'><tr><td valign='top'><table width='100%'><tr><td>aaaaa
<br> </td></tr><tr><td>
I want to get the aaaaa
part till <br>
or </td>
. I tried lots of patterns but didnt work. any help?
<tr id='ieconn3' >
<td><table width='100%'><tr><td valign='top'><table width='100%'><tr><td>aaaaa
<br> </td></tr><tr><td>
I want to get the aaaaa
part till <br>
or </td>
. I tried lots of patterns but didnt work. any help?
You shouldn’t try to use regular expressions to parse HTML as HTML is not a regular language and thus cannot be described with regular expressions. Use a proper HTML parser instead.
If you’re using XHTML, you can use SimpleXML to parse it as XML and query it with SimpleXMLElement::xpath. And for HTML documents, you can use the Simple HTML DOM Parser. And DOMDocument can even handle both XHTML and HTML.
As Gumbo pointed out, this will only result in a giant mess if you insist on using a regexp for this. However, if you are sure the HTML does not chance, this one will do the trick:
/<tr><td>(.*)<\/td><\/tr>/
use like this:
$string = "<tr id='ieconn3' >
<td><table width='100%'><tr><td valign='top'><table width='100%'><tr><td>aaaaa<br> </td></tr><tr><td>";
$matches = array();
preg_match("/<tr><td>(.*)<\\/td><\\/tr>/", $string, $matches);
print($matches[1]);