ktsixit
12-12-2008, 02:43 PM
Hi all,
I use a php script to edit and update content of an xml file. The php code is the following:
$fname = "new.xml";
$fhandle = fopen($fname,"r");
$filestring = file_get_contents($fname);
$target = '<title name="'.$row_new_to_edit['title'].'">';
$target .= '<text>'.$row_new_to_edit['text'].'</text></title>';
$newdata = '<title name="'.$_POST['title'].'">';
$newdata .= '<text>'.$_POST['text'].'</text></title>';
$newfile = str_replace($target, $newdata, $filestring);
$fhandle = fopen($fname,"w");
fwrite($fhandle,$newfile);
fclose($fhandle);
The script finds the $target string inside the xml file, and replaces it with the $newdata string.
The problem is that there can be -change line- and -space- characters inside he <text></text> tags. If such happens, the $target string can't be found inside the sml file. So what I need is something to make the str_replace function ignore changing lines and spaces inside strings?
How am I supposed to do that? Can you help me?
I use a php script to edit and update content of an xml file. The php code is the following:
$fname = "new.xml";
$fhandle = fopen($fname,"r");
$filestring = file_get_contents($fname);
$target = '<title name="'.$row_new_to_edit['title'].'">';
$target .= '<text>'.$row_new_to_edit['text'].'</text></title>';
$newdata = '<title name="'.$_POST['title'].'">';
$newdata .= '<text>'.$_POST['text'].'</text></title>';
$newfile = str_replace($target, $newdata, $filestring);
$fhandle = fopen($fname,"w");
fwrite($fhandle,$newfile);
fclose($fhandle);
The script finds the $target string inside the xml file, and replaces it with the $newdata string.
The problem is that there can be -change line- and -space- characters inside he <text></text> tags. If such happens, the $target string can't be found inside the sml file. So what I need is something to make the str_replace function ignore changing lines and spaces inside strings?
How am I supposed to do that? Can you help me?