Grab XML doc from folder and parse with PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
daelan
Forum Newbie
Posts: 2
Joined: Fri Sep 01, 2006 2:58 pm

Grab XML doc from folder and parse with PHP

Post by daelan »

I need to be able to use PHP to grab numerous xml documents from a folder on the server, parse them and then throw the data in a mysql database.

Can anyone point me in the right direction?

Thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

I need to be able to use PHP to grab numerous xml documents from a folder on the server
I like

Code: Select all

glob() and file_get_contents()
for getting a load of files.
parse them
Use DOM (not DOMXML that's old hat), XSTL or SAX (under XML in PHP manual).
daelan
Forum Newbie
Posts: 2
Joined: Fri Sep 01, 2006 2:58 pm

Post by daelan »

Thanks for the tips.
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

I have a useful function for getting information between 2 things

Code: Select all

function find($string,$opener,$closer) 
{	$part1 = explode($opener,$string);
	$part2 = explode($closer,$part1[1]);
	$result = $part2[0];
	return $result;
}
Usage:

Code: Select all

$string = "<stuff>stuff goes here</stuff>";
$stuff = find($string,"<stuff>","</stuff>");
It would return "stuff goes here" inside $stuff.

I use this in php4, since I have no fancy libraries and stuff.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

GWsux wrote:I have a useful function for getting information between 2 things

Code: Select all

function find($string,$opener,$closer) 
{	$part1 = explode($opener,$string);
	$part2 = explode($closer,$part1[1]);
	$result = $part2[0];
	return $result;
}
Usage:

Code: Select all

$string = "<stuff>stuff goes here</stuff>";
$stuff = find($string,"<stuff>","</stuff>");
It would return "stuff goes here" inside $stuff.

I use this in php4, since I have no fancy libraries and stuff.
I like that. Very much. :)
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

Thanks, Its the main reason my whole CMS works. It has tons of uses. I use it to read data out of files that are structured like XML.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Cause you could expand it into a DOM-like system. Wouldn't be too hard.
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

That's pretty much what I do.
Post Reply