Current location: Hot Scripts Forums » Programming Languages » PHP » Remove lines which have no specified values?


Remove lines which have no specified values?

Reply
  #1 (permalink)  
Old 07-13-09, 07:25 AM
Mythvn Mythvn is offline
Wannabe Coder
 
Join Date: Jan 2006
Posts: 111
Thanks: 2
Thanked 0 Times in 0 Posts
Remove lines which have no specified values?

I'm parsing a large text file and I want to remove lines that have no specified values. Eg, if a line doesn't have : "abc" or "def" then it will be taken out. Can anybody help me please? Thanks so much.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-13-09, 08:36 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
PHP Code:

<?php
$a 
fopen("test.txt","r");
while(!
feof($a)){if(preg_match("/abc|def/",$line=trim(fgets($a)))){echo $line."<br />";}}
fclose($a);
?>
__________________
Jerry Broughton

Last edited by job0107; 07-13-09 at 08:55 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-13-09, 08:56 AM
Mythvn Mythvn is offline
Wannabe Coder
 
Join Date: Jan 2006
Posts: 111
Thanks: 2
Thanked 0 Times in 0 Posts
Can I use preg_replace?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-13-09, 10:07 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Quote:
Originally Posted by Mythvn View Post
Can I use preg_replace?
I suppose you could if you want to replace one value with another.
I don't see why not.
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Auto Dealer Script nuzzle PHP 17 04-14-10 09:34 PM
[SOLVED] Friend to Friend Shortest Path sandeep.kumar Database 51 01-15-09 04:12 AM
PHP - Unable to remove items from a file AdrianLewis PHP 5 03-17-06 06:14 AM
MySQL table problem perleo PHP 9 12-16-03 02:16 PM


All times are GMT -5. The time now is 09:11 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.