dustinto Posted March 6, 2006 Share Posted March 6, 2006 I have info stored in an XML file and I want to parse it to a dynamic page (page.php?id={id})XML file is setup like<category id="something" name="name" address="bahh"...etc> <category id="something" name="name" address="bahh"...etc> <category id="something" name="name" address="bahh"...etc> I don't want the data to be put into a table (like most XML stuff seems to do). I think I know how to get all this to work I just need help getting the dynamic part of the page to work.I am guessing I am going to need some type of if statement, but I don't know where to start.(if anyone knows of a good web site/tutorial on this that would be great.)Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/4234-creating-a-dynamic-page-id/ Share on other sites More sharing options...
Steveo31 Posted March 7, 2006 Share Posted March 7, 2006 Not too clear on your post... can you give more examples, etc? Quote Link to comment https://forums.phpfreaks.com/topic/4234-creating-a-dynamic-page-id/#findComment-15185 Share on other sites More sharing options...
txmedic03 Posted March 8, 2006 Share Posted March 8, 2006 Well, assuming that your file is setup<category id="something" name="name" address="bahh"...etc><category id="something" name="name" address="bahh"...etc><category id="something" name="name" address="bahh"...etc>with each <category /> on a separate line then you could read the contents of it like this:[code]<?php$file = file("file.xml");if (is_array($file)) { while(list($key,$val)=each($file)) { if ( strtolower(substr(trim($val), 0, 9)) == "<category" ) { $start = strpos($val, "id=\"")+4; $end = strpos($val, "\"", $start); $id[$key] = substr($val, $start, $end); $start = strpos($val, "name=\"")+6; $end = strpos($val, "\"", $start); $name[$key] = substr($val, $start, $end); $start = strpos($val, "address=\"")+9; $end = strpos($val, "\"", $start); $addres[$key] = substr($val, $start, $end); } }}?>[/code]This still leaves a lot of room for error and may need to be adjusted slightly on where it begins and ends extracting your values, but this will give you the basic idea. I have not tested this code, it is just what I wrote on the fly, but it should do what you are looking for if I am not mistaken. It is supposed to give you three arrays which you can then sort in any manner you like and manipulate. If you need help with the manipulation or output of the arrays in some format, I would be happy to help.Happy coding! Quote Link to comment https://forums.phpfreaks.com/topic/4234-creating-a-dynamic-page-id/#findComment-15321 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.