poleposters Posted April 18, 2008 Share Posted April 18, 2008 Hi all, I have a flash page flip script which gets all the image data from an XML document. Is it possible to populate this document with PHP? I want to add it on to my users profile pages so that they can have a page flip photo album dynamically created from their images in my database. I've got most of the PHP basics down, but XML is new to me. I'm going to learn what I can, but in the mean time any advice would be appreciated. Cheers. Link to comment https://forums.phpfreaks.com/topic/101728-can-i-modify-an-xml-document-with-php/ Share on other sites More sharing options...
haku Posted April 18, 2008 Share Posted April 18, 2008 Yes, you can do it using fopen, fwrite, and fclose. Basically you build a string containing your XML: $string = "<indexes>" . PHP_EOL; $string .= "<index>" .PHP_EOL; $string .= "<element>element data</element>" . PHP_EOL; $string .= "</index>" . PHP_EOL; $string .= "</indexes>". PHP_EOL; The PHP_EOL causes a line break that makes your XML easier to read. You can leave them out if you want, they are not essential. Then, you open a file, write to it, and close the file: $open = fopen("file.xml", "w"); fwrite ($open, $string); fclose($open); This is super simplified, not complete (no doctype on the xml file etc), and not tested, so there may be some errors in there. But the idea is to show you how to do it, not write the code for you. Good luck, and post back here if you are having some troubles. Link to comment https://forums.phpfreaks.com/topic/101728-can-i-modify-an-xml-document-with-php/#findComment-520480 Share on other sites More sharing options...
poleposters Posted April 19, 2008 Author Share Posted April 19, 2008 Great! I've created my first file, But since I have to create a file for each registered user I need to give the file an individual name probably based on the user id. ie 35_file.xml Is this possible? Also what is the significance of "w" in the following line? $open = fopen("file.xml", "w"); Link to comment https://forums.phpfreaks.com/topic/101728-can-i-modify-an-xml-document-with-php/#findComment-521105 Share on other sites More sharing options...
dev Posted April 19, 2008 Share Posted April 19, 2008 w is using only for write to file. If you use 'r' you can only read a file. There's more functions. Like: 'w+' and 'r+' is same. With this you can read and write. Link to comment https://forums.phpfreaks.com/topic/101728-can-i-modify-an-xml-document-with-php/#findComment-521109 Share on other sites More sharing options...
haku Posted April 19, 2008 Share Posted April 19, 2008 I would suggest you read the three links I gave you in my last post. They will tell you exactly what is happening while you are using those commands, and will explain "r", "w" and others. Link to comment https://forums.phpfreaks.com/topic/101728-can-i-modify-an-xml-document-with-php/#findComment-521115 Share on other sites More sharing options...
poleposters Posted April 19, 2008 Author Share Posted April 19, 2008 Thank you. Didn't read carefully enough. I've tried renaming the file to be created with partial success. This is what I've tried. $businessid=35 $open = fopen("xml/$businessid._.file.xml", "w"); except the file created is 35._.file.xml. What I want to do is name the file is 35_file.xml Any ideas? Link to comment https://forums.phpfreaks.com/topic/101728-can-i-modify-an-xml-document-with-php/#findComment-521134 Share on other sites More sharing options...
chigley Posted April 19, 2008 Share Posted April 19, 2008 <?php $businessid = 35; $open = fopen("xml/{$businessid}_file.xml", "w"); ?> Link to comment https://forums.phpfreaks.com/topic/101728-can-i-modify-an-xml-document-with-php/#findComment-521136 Share on other sites More sharing options...
poleposters Posted April 19, 2008 Author Share Posted April 19, 2008 Thank you. I've been reading upon concatenation. But I have yet to see that. Very handy. Thank you. Link to comment https://forums.phpfreaks.com/topic/101728-can-i-modify-an-xml-document-with-php/#findComment-521139 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.