Page 1 of 1

PHP Find and Replace characters

Posted: Mon Jun 23, 2003 2:39 pm
by lynel
Can a person dump a text file into a database, then find and replace certain characters? How would you go about doing this...

Posted: Mon Jun 23, 2003 4:07 pm
by Galahad
I'm not sure that this is what you are looking for, but you could retrieve the data from the database and store it in a php variable, use something like str_replace or preg_replace to make your changes, then put it back in the database with a mysql update query.

Posted: Mon Jun 23, 2003 4:23 pm
by McGruff
The easiest option could be to find/replace in the text file itself.

string function

Posted: Mon Jun 23, 2003 5:41 pm
by Judas
:idea:

Code: Select all

<?php
$file="<!--your_file-->";

$old = file ($file);

foreach ($old as $line_num => $line) {
  //$word=explode(" ",$line);
  //maybe an second loop with the word array
  $line[]= str_replace ("<!--find_this-->","<!--replace_with_this-->",$line);

  }

$new=implode("\n",$line);
?>