Jan 03, 2009 | Under:
XML,
php
Want to display your (or maybe be someone else’s) public timeline using php? Ok, here’s the solution for it:
<?php
$username = “amanjain”;
$rssUrl = “http://twitter.com/statuses/user_timeline/$username.rss”;
$rss = @file_get_contents($rssUrl);
if($rss)
{
$xml = @simplexml_load_string($rss); Read the rest of this entry »
Dec 21, 2008 | Under:
XML,
php
Times may come when you want to parse an XML page with php .. or read feeds with php. “So, how to do it ?” .. is the question..
Here’s it:
$fileURL = “./fileName.xml”; //Specify the path(or Link of the xml file. )
$string = file_get_contents($fileURL); //This will load the wole content of xml file into the variable.
$xml = simplexml_load_string($string); //simplexml_load_string, loads the data inform of an object or returns false if there is a problem in xml
if($xml !== false) //checks weather xml was sucessfully loaded
{
//now suppose we want to list down all the attributes of tag FIRST ModulePrefs tag i.e <ModulePrefs …. ></…>
foreach($xml->ModulePrefs[0]->attributes() as $a => $b) \\ [0] means the first ModulePrefs tag
{
echo $a = $b \\here $a is the attribute and $b is the value.
}
}
Easy isn’t it?