Question regarding str_replace
Posted: Mon Oct 23, 2006 8:41 pm
Hi another question for the php guru's here. I am trying to write program that opens a serialized text file and either takes out certain words (this I would prefer) of at least replaces them with " ". It is not working to well. Here is what I have generally:
As always, thank you so much for your help and your patience. I have learned so much from this forum in the last week that it is really hard to believe (of course this forum also emphasizes how much more I need to learn).
Code: Select all
<? php
$eraseData = array(
'name' => " ",
'cart' => " ",
'date' => " "
);
$file = file("carts.txt"); //get the file as an array
foreach($file as $line)
{
$myline = trim($line); //remove any spaces
$current_cart = unserialize($myline); //unserialize the string and get the stored cart array
$switch_text_file = str_replace($current_cart,$eraseData,$current_cart); //make the replacement
//open text file and switch out reservation info with $eraseData
$cart_string = serialize($switch_text_file);
$fp = fopen("carts.txt","a");// append does not make sense here would write be better?
fwrite($fp,$cart_string);
fclose($fp);
}