# Formatting PHP

**URL:** <https://forum.kirupa.com/t/formatting-php/63807>\
**Category:** programming\
**Created:** [September 10, 2004, 3:23am UTC](https://forum.kirupa.com/t/formatting-php/63807 "2004-09-10T03:23:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tajmahal](https://avatars.discourse-cdn.com/v4/letter/t/cdc98d/32.png) [@tajmahal](https://forum.kirupa.com/u/tajmahal)\
**Post date:** [September 10, 2004, 3:23am UTC](https://forum.kirupa.com/t/formatting-php/63807/1 "2004-09-10T03:23:28Z")

</div>

I’m trying to update an XML file through some input fields. Users will put info into the inupt fields, hit ‘submit,’ and then their information will be loaded into the XML file. To achieve this, I’m using PHP. The PHP file i’m modifying to achieve this is the same one used in the XML Guestbook tutorial found on this site. The PHP updates the XML file perfectly; no problems there.

However, when the PHP writes the XML, everything is put into one really long string. This is where my problem lies. I need a new line between the opening tag of the XML file (\<?xml version=“1.0”?\>) and the rest of the file. I need this new line so my XML file can be read by another .swf (for some reason, this .swf wont read the XML unless the rest of the XML data is on a different line than the first tag). So basically, i want the PHP to load to input data into the XML nodes, yet insert a new line after the \<?xml version=“1.0”?\> tag.

My PHP file follows:

> \<?php  
> $xmlString = $HTTP\_RAW\_POST\_DATA;  
> if (is\_null($xmlString)) {  
> print “No data was sent”;  
> }  
> else {  
> $file = fopen(“cal.xml”, “w+”) or die(“Can’t open XML file”);  
> if(!fwrite($file, $xmlString)){  
> print “Error writing to XML-file”;  
> }  
> print $xmlString."  
> ";  
> fclose($file);  
> }  
> ?\>

Here’s my XML file before being updated by the PHP:

> \<?xml version=“1.0”?\>  
> _[color=gray]Here’s where i need the space, all the rest of the file can be on one line[/color]_  
> \<Calendar\>  
> _[color=gray]here’s where the new xml info from my input fields will go[/color]_  
> \</Calendar\>

Any ideas? All i need is a new line to be put in before the new inputs are put in. I’d appreciate any help. Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 10, 2004, 8:37am UTC](https://forum.kirupa.com/t/formatting-php/63807/2 "2004-09-10T08:37:23Z")

</div>

Not sure however u could first write that string that u need.

\<?xml version=“1.0”?\>

than reopen the file with fopen($file, “a”) and add it from the line u whish it to start writing 🙂

+a

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 10, 2004, 12:23pm UTC](https://forum.kirupa.com/t/formatting-php/63807/3 "2004-09-10T12:23:14Z")

</div>

doesn’t seem to be working… can you be more specific?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 10, 2004, 6:37pm UTC](https://forum.kirupa.com/t/formatting-php/63807/4 "2004-09-10T18:37:32Z")

</div>

Whats ure code now ?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 18, 2004, 9:45pm UTC](https://forum.kirupa.com/t/formatting-php/63807/5 "2004-09-18T21:45:41Z")

</div>

looks something like this…

```php
 
<?php 
$xmlString = $HTTP_RAW_POST_DATA; 
if (is_null($xmlString)) { 
print "No data was sent"; 
} 
else { 
print "
"
$file = fopen("cal.xml", "a+") or die("Can't open XML file"); 
if(!fwrite($file, $xmlString)){ 
print "Error writing to XML-file"; 
}
print $xmlString."
"; 
fclose($file); 
} 
?> 

```

sorry i took so long to reply, i still need help though…
