PHP Find and Replace characters
Moderator: General Moderators
PHP Find and Replace characters
Can a person dump a text file into a database, then find and replace certain characters? How would you go about doing this...
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.
string function
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);
?>