|
Posted by Mark Cain on 05/04/05 15:08
This should get you started:
$old_data = file_get_contents('./test.txt');
$my_data = "foo bar";
$pattern = '/(.*)(<\/.*>)$/i';
$replacement = '$1' . $my_data . '$2';
$new_data = preg_replace($pattern, $replacement, $old_data);
echo $new_data;
or a little more succinctly
$my_data = "foo bar";
$new_data = preg_replace('/(.*)(<\/.*>)$/i', '$1' . $my_data . '$2',
file_get_contents('./test.txt'));
echo $new_data;
Mark Cain
----- Original Message -----
From: "Jared Sherman" <jaredsherman@cox.net>
To: <php-general@lists.php.net>
Sent: Tuesday, May 03, 2005 2:00 AM
Subject: [PHP] php newbie question with xml files
> I have an xml document storing some data I need. What I want to do is
this:
> 1. Scan to the end of the file.
> 2. Find the closing tag.
> 3. Insert a new entry in before the closing tag.
>
> I've tried:
> 1. Creating new files and renaming them to be the original.
> 2. Writing the file to a dummy file and insert my lines part way through
> then finish the last tag.
>
> My problem is I'm looking for a </endtag> and it comes up as endtag. Is
> there anyway to force PHP to read the .xml file as a text file so it wont
> strip off the xml tag information?
>
> I've used fopen with fgets and fwrite, and file with fwrite
>
> Jared Sherman
> Totally lost newbie
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Navigation:
[Reply to this message]
|