Re: [PHP] php newbie question with xml files

2005-05-04 Thread Mark Cain
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 [EMAIL PROTECTED]
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



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php newbie question with xml files

2005-05-04 Thread Mark Cain
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 [EMAIL PROTECTED]
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



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php newbie question with xml files

2005-05-04 Thread disguised.jedi
 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.

There are specific classes and functions in the PHP core that can help
you do just this.

 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.

I don't think this is the right approach to take.  Maybe using the DOM
and/or the XML Parser built-in to php would help you.

 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

Again, this isn't the approach to take.  There are built-in functions
for this sort of thing, as well as classes on PEAR that will help you.
 Try google!

Read through all of this and decide which approach you want to take
before you start anything...

If you use Windows or compile PHP as an Apache module in Linux, you're
all set with the XML Parser.  If not, you'll need to get the library
according to the directions in the manual.

http://www.php.net/xml

Read everything in that thoroughly, and understand it before you
continue with this approach.  Copy and play with the examples to see
how it all works.  If you'd rather handle things in an environment
designed to create and manipulate XML dynamically, rather than just
read and insert raw strings, keep reading.

You can get the DOM XML working easily in Windows, and even easier in
a GNOME environment on a linux box.  The manual has excellent
instructions.

http://www.php.net/domxml

This extension is Object-Oriented (OO), and if you don't know what
that is, you better read up on it before you try this out.  If you do,
and have an OK understanding of how OO works in PHP, then read on!  If
not, read the article

http://www.php.net/oop

Now, understand that DOM XML is very particular about the syntax and
such in an XML file.  The file MUST start with the XML declaration
(without quotes) ?xml version=1.0 in order for DOM to try and use
it.

Use the functions to read right through it all.  You'll find that this
is probably exactly what you need!

I'd use DOM XML personally.  I included the other in case you didn't
want to have to install everything.

Have fun, and good luck with PHP!

-- 
[EMAIL PROTECTED]

PHP rocks!
Knowledge is Power.  Power Corrupts.  Go to school, become evil

Disclaimer: Any disclaimer attached to this message may be ignored. 
However, I must say that the ENTIRE contents of this message are
subject to other's criticism, corrections, and speculations.

This message is Certified Virus Free

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php newbie question with xml files

2005-05-04 Thread Jason Barnett
PHP5:
http://php.net/manual/en/ref.dom.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] php newbie question with xml files

2005-05-03 Thread Jared Sherman
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