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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • meofcors
    New Member
    • May 2012
    • 2

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

    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



    Code:
    $m=file_get_contents ('sample.txt');
    $comp=file('list.txt');
    for ($x=0; $x<= count($comp); $x++)
    {
       $comp[$x] = trim(strtolower($comp[$x]));
       $c =$comp[$x];
       $rep=str_replace(" ","_",$c);
       $rep=" ".$rep." "; 
       $m =preg_replace($c,$rep,$m);   
    
    }
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I don't see the error text.

    Comment

    • meofcors
      New Member
      • May 2012
      • 2

      #3
      i get this and then my browser hangs
      Warning: preg_replace() [function.preg-replace]: No ending delimiter ''' found in C:\xampp\htdocs \forbtp\codever sions\latest\te st.php on line 146

      Comment

      Working...