PHP Create text file

They have: 82 posts

Joined: Oct 2001

OK Guys I am an ASP guy.

I need to write a file in PHP.

The file needs to be an XML document. In ASP I just create a FileSystem Object and call the writeline method.

How would I write this in PHP?

Thanks,

Mike

Blessed is the man who fears the LORD, who delights greatly in his commandments. Psalms 112:1

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

The PHP equivalent to ASP's filesystem:
http://us4.php.net/manual/en/ref.filesystem.php

<?php
$fp
= fopen(\"/path/to/file.txt\", 'w+');
// or
//
$fp = fopen(\"c:\path\to\file.txt\", 'w+');

if (
$fp) {
    fwrite(
$fp, \"<test1></test1>\");
    fwrite(
$fp, \"<test2></test2>\");
    close(
$fp);
}
?>
I don't remember if it appends a newline or not.

Mark Hensler
If there is no answer on Google, then there is no question.

He has: 296 posts

Joined: May 2002

I believe you have to add \n after the first entry. Not sure myself, either.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.