Jump to content

Get text between repeating <tr></tr> tags


Recommended Posts

Hi Bros,

 

I got head-ache trying to solve this problem. I have a structure like this:

<tr>
<td width="10%" bgcolor="#FFFFFF"><font class="bodytext9">17-Aug-2013</font></td>
<td width="4%" bgcolor="#FFFFFF" align=center><font class="bodytext9">Sat</font></td>
<td width="4%" bgcolor="#FFFFFF" align="center"><font class="bodytext9">5 PM</font></td>
<td width="15%" bgcolor="#FFFFFF" align="center"><a class="black_9" href="teams.asp?teamno=766&leagueNo=115">XYZ Club FC</a></td>
<td width="5%" bgcolor="#FFFFFF" align="center"><font class="bodytext9"><img src="img/colors/white.gif"></font></td>
<td width="5%" bgcolor="#FFFFFF" align="center"></td>
<td width="5%" bgcolor="#FFFFFF" align="center"><font class="bodytext9">vs</font></td>
<td width="5%" bgcolor="#FFFFFF" align="center"></td>
<td width="5%" bgcolor="#FFFFFF" align="center"><font class="bodytext9"><img src="img/colors/orange.gif"></font></td>
<td width="15%" bgcolor="#FFFFFF" align="center"><a class="black_9" href="teams.asp?teamno=632&leagueNo=115">ABC Football Club</a></td>
<td width="15%" bgcolor="#FFFFFF" align="center"><a href="pitches.asp?id=151" class=list><u>APSM Pitch </u></a></td>
<td width="4%" bgcolor="#FFFFFF" align="center"><a target="_new" href="matchpreview_frame.asp?matchno=20877"><img src="img/matchpreview_symbol.gif" border="0"></a></td>
</tr>

this format will repeat many times with different text contain, sometime, some text contain is similar. I need to extract ONLY the FIRST group of this format, where it contain "ABC Football Club" the FIRST TIME (because it could appear many times later also). How do I do that and extract the text on each line ? 

Link to comment
https://forums.phpfreaks.com/topic/281115-get-text-between-repeating-tags/
Share on other sites

How are you getting the data for the rows? From a database?  You may be able to use the GROUP BY clause.  We will need some more precise info from you to help further.  Also you really need to use css to format the table rather than the horrible repeated inline styling you have now.

well.. you didn't really provide details about how you wanted the text to be returned.. but here is one way to do it:

 

preg_match('~<tr>.*?ABC Football Club.*?</tr>~is',$content,$match);
if (isset($match[0])) $text = strip_tags($match[0]);
$content is the text you are trying to extract the info from, and $text will then contain something like this:
 
17-Aug-2013
Sat
5 PM
XYZ Club FC


vs


ABC Football Club
APSM Pitch
 
Basically the code grabs the first tr block that has that "ABC Football Club" string within it, and then strips all the html tags from it, leaving the text and linebreaks.  From there, it kinda depends on what you're going for, but I assume you don't need help as far as string manipulation..  
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.