TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 01-18-2008, 01:42 AM   #1 (permalink)
The Acquainted
 
buildakicker's Avatar
 
Join Date: Jan 2008
Posts: 119
Thanks: 21
buildakicker is on a distinguished road
Terminal Writing to XML file

Hi All,

I was originally going to use .txt files, then thought it'd be way better to use .xml files. So, now I have to write to them. My issue is, how to read between the "lines". Right now I have:

PHP Code:
if(isset($_POST['newpost'])){
    
//get the info from the form, post to text file.
    
$title stripslashes($_POST['title']);
    
$category stripslashes($_POST['category']);
    
$body stripslashes($_POST['body']);
    
    
//add data XML style
    
$data "<post>" "\n" "<category>"$category "</category>" "\n" "<title>" $title "</title>" "\n" "<date>" $todaysdate "</date>" "\n" "<body>" "\n"$body "</body>" "\n" "</post>""\n\r";
    
    
//add data to CSV Text File
    //$data = $category . "||" . $title . "||" . $body . "\n";
    //open file and store contents
    
$file fopen('posts.xml','a+');
    if (!
$file) {echo 'ERROR: Unable to open file.'; exit;} 
    
//post current post, then write $currentdata back to file
    // Write the data to the file
    
fwrite($file$data);
    
// Close the file
    
fclose($file);
    
    
$postupdated "You have created a new post!";

...which posts fine to the file. However, if I have:

Code:
<?xml version="1.0" standalone="yes"?>
<posts>
  <post>
    <title>Some people like meat.</title>
    <category>Meat</category>
    <pubDate>2008-January-15</pubDate>
  </post>
</posts>
What is the best way to get the <posts> and then write to it without messing the xml file up?
Code:
<?xml version="1.0" standalone="yes"?>
<posts>
     //insert $data here
</posts>
What I am thinking is I should get all the <post> data from the XML file and store it in $dataxml then add $data to it, then write it back to the file.

Would that be the best way?

Thanks
__________________
SkiLeases.com
buildakicker is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 04:52 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design