change a word in a line of text file with php -


i need change word after maildir, in exemple null of line : (the word null can word.)

  [3]=>   string(42) "spam * ^subject: \[spam\].* maildir/.null/" 

i use code :

if($filecontent = file_get_contents($filename)){      $repertoire = "spam";     $tab = explode("#", trim($filecontent));     $tab[3] = preg_replace("#maildir/*#", 'maildir/.'.$repertoire.'/', $tab[3]);      var_dump($tab); 

but have

  string(48) "spam * ^subject: \[spam\].* maildir/.null/.spam/" 

how can change in maildir/.spam because .null in excess.

  string(48) "spam * ^subject: \[spam\].* maildir/.spam/" 

you can this:

 preg_replace('~maildir/\k\.null/(?=\.spam)~', '', $string); 

or word:

 preg_replace('~maildir/\k[\w.-]++/(?=\.spam)~', '', $string); 

i have tested with:

$string = <<<lod spam * ^subject: \[spam\].* maildir/.null/.spam/ lod; echo preg_replace('~maildir/\k[\w.-]++/(?=\.spam)~', '', $string).'<br/>'; echo preg_replace('~maildir/\k\.null/(?=\.spam)~', '', $string).'<br/>'; 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -