replace / substitute a tag value from one xml file to another xml using php -


need replace / substitute tag value 1 xml file xml

i need replace tag value xml file using php

file 1

<complete>   <list>     <change>hello</change>     <manage>world</manage>   </list>   <list>     <change>hello1</change>     <manage>world1</manage>   </list>   <list>     <change>hello2</change>     <manage>world2</manage>   </list> </complete> 

file 2

<complete>   <list>     <change>duplicate</change>     <manage>duplicate</manage>   </list>   <list>     <change>duplicate1</change>     <manage>duplicate1</manage>   </list>   <list>     <change>duplicate2</change>     <manage>duplicate2</manage>   </list> </complete> 

o/p

<complete>   <list>     <change>duplicate</change>     <manage>world</manage>     <change>duplicate1</change>     <manage>world1</manage>     <change>duplicate2</change>     <manage>world2</manage>    </list> </complete> 

i need tag manage replaced 1st xml file 2nd xml file.

here go:

$file1 = file_get_contents("file1.xml"); $file2 = file_get_contents("file2.xml");  preg_match_all('%<manage>(.*?)</manage>%m', $file1, $match, preg_pattern_order); $xmlmatch = $match[1][0];  $newxml = preg_replace('%<manage>.*?</manage>%m', "<manage>$xmlmatch</manage>", $file2);  file_put_contents("file2.xml", $newxml); 

note: make sure file2.xml writable.


after processing file2.xml looks like:

<complete>   <list>     <change>duplicate</change>     <manage>world</manage>   </list> </complete> 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -