LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   php problem with strings (https://www.linuxquestions.org/questions/programming-9/php-problem-with-strings-370529/)

graziano1968 10-07-2005 01:56 AM

php problem with strings
 
Hello

I have this problem


varialble $list contains this

Code:

<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

graziano1968 10-07-2005 02:24 AM

I found solution

Code:

$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>';
  }
}


spooon 10-07-2005 04:16 AM

How about something like
Code:

echo preg_replace('|<tr>.*?host2\.com.*?</tr>|', '', $list);

graziano1968 10-07-2005 10:30 AM

your code doesn't work ... I don't know why but I had same problem using preg_match and preg_match all

perhaps because pregmatch checks only on a single line , but I am not sure .

spooon 10-07-2005 01:30 PM

Quote:

Originally posted by graziano1968
perhaps because pregmatch checks only on a single line
Oh yeah, I forgot; you should put in some flags (specifically the "s" flag allows the dot to match newlines):
Code:

echo preg_replace('|<tr>.*?host2\.com.*?</tr>|ms', '', $list);

graziano1968 10-07-2005 02:10 PM

i didn't know the s flaf , thank you.

Where can I read on php manual about these flags ?


All times are GMT -5. The time now is 03:46 PM.