Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

regular expression help

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

regular expression help

Postby jessevitrone » Mon Jul 14, 2003 11:53 am

I have an xml string that I have to parse that looks like this:

<data><text>Sample Text</text><price>9.00</price></data>

I'd like to be able to pull the data from that, and have it go into an array to look like this:

$data["text"] = "Sample Text";
$data["price"] = "9.00";

The problem is that "text" and "price" can be anything, and any number of sub elements in the <data> tags.

I know there are ways to do this with regular expressions, but I can't remember :(

Any suggestions?

Thanks in advance.
jessevitrone
New php-forum User
New php-forum User
 
Posts: 4
Joined: Fri Jul 11, 2003 6:59 am

Postby swirlee » Mon Jul 14, 2003 12:18 pm

There are a good number of PHP XML parsing scripts available. No need to use regex. A quick googling revealed:


.. they all pretty much do the same thing.

Or, if you're into doing it from scratch, check out PHP's very ample XML parser functions.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

thanks

Postby jessevitrone » Mon Jul 14, 2003 12:20 pm

Thanks, I'll take a look at those.
jessevitrone
New php-forum User
New php-forum User
 
Posts: 4
Joined: Fri Jul 11, 2003 6:59 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron