Page 1 of 1

Grab XML doc from folder and parse with PHP

Posted: Fri Sep 01, 2006 3:00 pm
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

Posted: Fri Sep 01, 2006 3:58 pm
by volka

Posted: Fri Sep 01, 2006 9:33 pm
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).

Posted: Fri Sep 01, 2006 10:16 pm
by daelan
Thanks for the tips.

Posted: Sat Sep 02, 2006 1:23 pm
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.

Posted: Sat Sep 02, 2006 1:35 pm
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. :)

Posted: Sat Sep 02, 2006 1:57 pm
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.

Posted: Sat Sep 02, 2006 2:06 pm
by Ollie Saunders
Cause you could expand it into a DOM-like system. Wouldn't be too hard.

Posted: Sat Sep 02, 2006 2:45 pm
by toasty2
That's pretty much what I do.