Samuz Posted March 1, 2012 Share Posted March 1, 2012 Example is: https://twitter.com/statuses/user_timeline/kevinhart4real.xml I have all the relevant information I need that i'd like to go in the field, I just need to know how to dynamically create the file with the content and have it update at specific intervals. Any one have any ideas (with PHP) So far I have come up with this: $link = mysql_connect('localhost','root',''); mysql_select_db('test',$link); $result = mysql_query('SELECT `nationid`,`ruler`,`nation`, `resource1`, `resource2`, `alliance` FROM `nation`'); $doc = new DomDocument('1.0'); $root = $doc->createElement('nationlist'); $root = $doc->appendChild($root); while($row = mysql_fetch_assoc($result)) { $nation= $doc->createElement('nation'); $nation = $root->appendChild($nation); foreach($row as $fieldname => $fieldvalue) { $child = $doc->createElement($fieldname); $child = $car->appendChild($child); //add data to the new element $value = $doc->createTextNode($fieldvalue); $value = $child->appendChild($value); } } $doc->save("nations.xml"); Now that generates 1 .xml file with all the details returned from my query. (also don't bash me for using mysql, it's a quick test) What I would like to do is create a new file for each record in my table and have only the values in that recorded saved to its respective file. Quote Link to comment https://forums.phpfreaks.com/topic/258038-creating-twitter-like-xml-feed/ Share on other sites More sharing options...
trq Posted March 1, 2012 Share Posted March 1, 2012 Why do you need to create any actual files? PHP can generate the xml when a request is made, just as it is generally used to generate html when a request is made. Quote Link to comment https://forums.phpfreaks.com/topic/258038-creating-twitter-like-xml-feed/#findComment-1322713 Share on other sites More sharing options...
Samuz Posted March 1, 2012 Author Share Posted March 1, 2012 Why do you need to create any actual files? PHP can generate the xml when a request is made, just as it is generally used to generate html when a request is made. Hi there thorpe. I need to generate actual files, because the content within them need to be specific to the actual user account. Would you recommend another solution for my situation? Quote Link to comment https://forums.phpfreaks.com/topic/258038-creating-twitter-like-xml-feed/#findComment-1322716 Share on other sites More sharing options...
laffin Posted March 1, 2012 Share Posted March 1, 2012 You don't need to generate files, as Thorpe said php is dynamic, so it can generate the file content on the fly. with a bit of htaccess help to map xml urls to a php script (http://mysite.com/user.xml), or path_info (http://mysite.com/timeline.php/user.xml)(both using apache, other webservers you will have to lookup how to create a virtual file mapping) or just use url parameters (http://mysite.com/timeline.php?u=user). To generate actual files at specific intervals, you will probably looking at cron with a long running php process, or someway to update users while browsing your site. Of all Thorpe's suggestion is by far the easiest method. Quote Link to comment https://forums.phpfreaks.com/topic/258038-creating-twitter-like-xml-feed/#findComment-1322724 Share on other sites More sharing options...
Samuz Posted March 1, 2012 Author Share Posted March 1, 2012 You don't need to generate files, as Thorpe said php is dynamic, so it can generate the file content on the fly. with a bit of htaccess help to map xml urls to a php script (http://mysite.com/user.xml), or path_info (http://mysite.com/timeline.php/user.xml)(both using apache, other webservers you will have to lookup how to create a virtual file mapping) or just use url parameters (http://mysite.com/timeline.php?u=user). To generate actual files at specific intervals, you will probably looking at cron with a long running php process, or someway to update users while browsing your site. Of all Thorpe's suggestion is by far the easiest method. Thanks that solution would make more sense now that I think of it. Now if I want to use url parameters, all i'd have to do is use the $GET array right? (Ensuring everything is sanitized of course) Quote Link to comment https://forums.phpfreaks.com/topic/258038-creating-twitter-like-xml-feed/#findComment-1322735 Share on other sites More sharing options...
laffin Posted March 1, 2012 Share Posted March 1, 2012 Correct, and you will have to use header('Content-Type: text/xml'); to dictate that the content being delivered is an xml file and be handled by the browser appropriately Quote Link to comment https://forums.phpfreaks.com/topic/258038-creating-twitter-like-xml-feed/#findComment-1322773 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.