# Editing xml via php

**URL:** <https://forum.kirupa.com/t/editing-xml-via-php/317801>\
**Category:** Uncategorized\
**Created:** [January 3, 2011, 11:47am UTC](https://forum.kirupa.com/t/editing-xml-via-php/317801 "2011-01-03T11:47:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![capdetrons](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@capdetrons](https://forum.kirupa.com/u/capdetrons)\
**Post date:** [January 3, 2011, 11:47am UTC](https://forum.kirupa.com/t/editing-xml-via-php/317801/1 "2011-01-03T11:47:56Z")

</div>

Hello,  
I’m using this script to change the IP settings for a server application that won’t run if the xml has the version declaration tag:  
\<?php  
$ip = getenv(“REMOTE\_ADDR”) ;  
$dom = new DOMDocument();  
$dom-\>formatOutput = true;  
$root = $dom-\>createElement(“ServerSettings”);  
$dom-\>appendChild($root);  
$IP = $dom-\>createElement(“IP”);  
$root-\>appendChild($IP);  
$text = $dom-\>createTextNode("$ip");  
$IP-\>appendChild($text);  
$Port = $dom-\>createElement(“Port”);  
$root-\>appendChild($Port);  
$text = $dom-\>createTextNode(“9875”);  
$Port-\>appendChild($text);  
print $dom-\>saveXML($root);  
$dom-\>save(“ServerSettings.xml”)  
?\>

it echoes properly, but still adds the declaration version line on overwriting the ServerSettings file:  
echo ex:  
\<ServerSettings\>  
\<IP\>88.8.36.147\</IP\>  
\<Port\>34\</Port\>  
\</ServerSettings\>  
Can anyone lend me a hand? Or suggest any tutorial?
