Page 1 of 1

looping through and parsing text

Posted: Wed Aug 01, 2012 9:37 am
by inosent1
hi

after pulling some text, each time there is only one occurrence of:

Code: Select all

$clause1 = "<th class=title>Data</th></tr></thead><tr><td>&nbsp;</td></tr>"; 

//(i am adding the variable)
and

Code: Select all

$clause2 = "</div><div id=page_select class=center></div>";
in between the two statements noted above is this:

Code: Select all

<tr><td class=no>1</td> 
<td class=name>smith</td> 
</tr>
<tr><td class=no>2</td> 
<td class=name>jones</td> 
</tr>
</table>

how can i tell php to:

"look in between $clause1 and $clause2 and find each instance of and find what is in between:

<tr><td class=no>

and

</td>
<td class=name>"

and then:

"look in between $clause1 and $clause2 and find each instance of and find what is in between:

<tr><td class=name>

and

</td>
</tr>
<tr><td class=no>"



tia

Re: looping through and parsing text

Posted: Wed Aug 01, 2012 10:01 pm
by requinix
Use something like DOMDocument or (if it's valid XHTML) SimpleXML to traverse the DOM hierarchy. Regular expressions are the wrong tool for this kind of work.