By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

How to find pharses stored in a file in another large text and replace them

P: 2
i have a text file say "list.text" containing phrase that is words and spaces, each phrase is in a new line.
I have a large number of text files in the form of paragraphs of size app 2mb each,i need to find the phrases existing in the list.text in every file and replace them with phrases having _ in place of spaces.
my code below shows error i cannot comprehend something related to memory.PLZ help



Expand|Select|Wrap|Line Numbers
  1. $m=file_get_contents ('sample.txt');
  2. $comp=file('list.txt');
  3. for ($x=0; $x<= count($comp); $x++)
  4. {
  5.    $comp[$x] = trim(strtolower($comp[$x]));
  6.    $c =$comp[$x];
  7.    $rep=str_replace(" ","_",$c);
  8.    $rep=" ".$rep." "; 
  9.    $m =preg_replace($c,$rep,$m);   
  10.  
  11. }
  12.  
May 9 '12 #1
Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,369
I don't see the error text.
May 9 '12 #2

P: 2
i get this and then my browser hangs
Warning: preg_replace() [function.preg-replace]: No ending delimiter ''' found in C:\xampp\htdocs\forbtp\codeversions\latest\test.ph p on line 146
May 9 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.