|
Posted by Noodle on 07/18/06 08:13
You will have to read the whole file to perform this task, but if your
using PHP5 this can be done in 1 step, using the get
file_get_contents() method to read the xml document into a string.
The following code will make the value change, and it isn't much
trouble to do...
<?php
# Set Values
$my_file = 'myfile.xml';
$new_value = 'Test updated';
# Get file contents
$xml = file_get_contents($my_file);
# Regex
$xml = preg_replace('<exo id="(.*)" value="(.*)" />', "exo id=\"$1\"
value=\"$new_value\" /", $xml);
# Write file out again
file_put_contents($my_file, $xml);
?>
jhullu@gmail.com wrote:
> Hi all
>
> can I update a xml node AND write the new value in a file witout
> re-write all the file ?
>
> sample :
>
> my xml file :
>
> <sample>
> <exo id="1" value="Test" />
> </sample>
>
> i want to modify the file like
>
> <sample>
> <exo id="1" value="Test updated" />
> </sample>
>
> is it possible ?
Navigation:
[Reply to this message]
|