looping through and parsing text

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
inosent1
Forum Commoner
Posts: 97
Joined: Wed Jan 28, 2009 12:18 pm

looping through and parsing text

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: looping through and parsing text

Post 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.
Post Reply