find a word and delete

Reply

Join Date: Mar 2009
Posts: 37
Reputation: ruwanaru is an unknown quantity at this point 
Solved Threads: 1
ruwanaru ruwanaru is offline Offline
Light Poster

find a word and delete

 
0
  #1
May 3rd, 2009
what i want to do is find a word from a text file and delete that word using php plzzzzzzzzz help me.........

i can find the word using this codes

  1. $handle = file_get_contents("files.txtl",NULL);
  2. $a="first";
  3. $a=substr_replace($a, '0', 0);
  4. $a=explode(" ",$a);
  5. $c=0;
  6. foreach($a as $y){
  7. if (stristr($handle,"$a[$c]")) $b[]= 'yes';
  8. else $b[]='no';
  9. $c++;
  10. }
  11. if (in_array("no",$b)) echo '<br><br>did not match';
  12. else echo '<br><br>we have a match';
Last edited by ruwanaru; May 3rd, 2009 at 12:05 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 37
Reputation: ruwanaru is an unknown quantity at this point 
Solved Threads: 1
ruwanaru ruwanaru is offline Offline
Light Poster

Re: find a word and delete

 
0
  #2
May 3rd, 2009
hellooooooo any 1 to help me...............
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 141
Reputation: robothy is an unknown quantity at this point 
Solved Threads: 19
robothy robothy is offline Offline
Junior Poster

Re: find a word and delete

 
0
  #3
May 3rd, 2009
  1. $strText = file_get_contents( 'file.txt' );
  2.  
  3. $strFind = 'word';
  4.  
  5. $blMatch = false;
  6.  
  7. if( preg_match( "/$strFind/", $strText ) ) {
  8. <blockquote>$blMatch = true;
  9.  
  10. $strText = str_replace( $strWord, '', $strText );</blockquote>}

That will tell you if your word is found, and it will remove it from the string.

R.
Last edited by Ezzaral; May 3rd, 2009 at 3:18 pm. Reason: Fixed code tag
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 37
Reputation: ruwanaru is an unknown quantity at this point 
Solved Threads: 1
ruwanaru ruwanaru is offline Offline
Light Poster

Re: find a word and delete

 
0
  #4
May 3rd, 2009
$strWord
this is a undefined index
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 141
Reputation: robothy is an unknown quantity at this point 
Solved Threads: 19
robothy robothy is offline Offline
Junior Poster

Re: find a word and delete

 
0
  #5
May 3rd, 2009
Oops, meant to be $strFind.

R
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC