PDA

View Full Version : working with strings


graziano
10-07-2005, 08:01 AM
Hello

I have this problem


varialble $list contains this


<tr> <td><FONT COLOR="#336699"><B><b>anonymous@host2.com</b></font></b></td>
<td><a href="editquota.html?acct=ftp"><img src="/frontend/test/images/quota.jpg" border=0></a></td><td colspan=2><img src="/frontend/test/images/mainacct.jpg"></td>
</tr>


<tr> <td><FONT COLOR="#336699"><B><b>ftp3@host1.com</b></font></b></td>
<td><a href="editquota.html?acct=ftp"><img src="/frontend/test/images/quota.jpg" border=0></a></td><td colspan=2><img src="/frontend/test/images/mainacct.jpg"></td>
</tr>

<tr> <td><FONT COLOR="#336699"><B><b>ftp2@host2.com</b></font></b></td>
<td><a href="editquota.html?acct=ftp"><img src="/frontend/test/images/quota.jpg" border=0></a></td><td colspan=2><img src="/frontend/test/images/mainacct.jpg"></td>
</tr>

<tr> <td><FONT COLOR="#336699"><B><b>ftp1@host1.com</b></font></b></td>
<td><a href="editquota.html?acct=ftp"><img src="/frontend/test/images/quota.jpg" border=0></a></td><td colspan=2><img src="/frontend/test/images/mainacct.jpg"></td>
</tr>


Before echo $list , I wish to remove from $list all table rows (from <tr> to </tr>) which contain "host2.com" . How to do that ? I tried using preg_match or preg_match_all but I am not able to find a solution .



Any help please ?
Thank you

graziano
10-07-2005, 08:24 AM
I found a solution



$parts = explode("</tr>", $list);
$alfa1= count ($parts);
$alfa1=$alfa1-1;

for($i = 0; $i < $alfa1; $i++) {
if (!ereg ("host2.com", $parts[$i]) )

{
echo $parts[$i] . '</tr>';
}
}

pjleonhardt
10-07-2005, 11:06 AM
Yes i answered your question over on phpbuilder.com :D :D

Thanks for updating this one as well, so someone else doesn't spend the time. It's appreciated :thumbsup: