LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-07-2005, 01:56 AM   #1
graziano1968
Member
 
Registered: Sep 2004
Posts: 223

Rep: Reputation: 30
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
 
Old 10-07-2005, 02:24 AM   #2
graziano1968
Member
 
Registered: Sep 2004
Posts: 223

Original Poster
Rep: Reputation: 30
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>'; 
  } 
}
 
Old 10-07-2005, 04:16 AM   #3
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
How about something like
Code:
echo preg_replace('|<tr>.*?host2\.com.*?</tr>|', '', $list);
 
Old 10-07-2005, 10:30 AM   #4
graziano1968
Member
 
Registered: Sep 2004
Posts: 223

Original Poster
Rep: Reputation: 30
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 .
 
Old 10-07-2005, 01:30 PM   #5
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
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);
 
Old 10-07-2005, 02:10 PM   #6
graziano1968
Member
 
Registered: Sep 2004
Posts: 223

Original Poster
Rep: Reputation: 30
i didn't know the s flaf , thank you.

Where can I read on php manual about these flags ?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to find duplicate strings in vertical column of strings markhod Programming 7 11-02-2005 04:04 AM
Problem the Strings in C++ gjagadish Programming 4 10-15-2005 03:45 AM
Using single quotes vs double quotes in PHP strings vharishankar Programming 6 07-11-2005 11:41 AM
parsing strings problem McB Programming 6 04-19-2004 09:50 AM
Problem with strings in Red Hat 8.0 smriti Linux - General 1 03-03-2003 07:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration