Graxeon Posted December 31, 2008 Share Posted December 31, 2008 I can get the title from this: <rss version="2.0"> <channel> <title>Desc</title> </channel> </rss> By using: list($node) = $sxml->xpath('/rss/channel/title'); But how can I call "google" from this using the same method? <rss version="2.0"> <channel> <title>Desc</title> <link auto="false" guide="false" timer="1s" path="google"> </channel> </rss> Quote Link to comment https://forums.phpfreaks.com/topic/138946-solved-how-to-call-this-with-simplexml_load/ Share on other sites More sharing options...
Graxeon Posted December 31, 2008 Author Share Posted December 31, 2008 Does anyone know how? Quote Link to comment https://forums.phpfreaks.com/topic/138946-solved-how-to-call-this-with-simplexml_load/#findComment-727006 Share on other sites More sharing options...
premiso Posted December 31, 2008 Share Posted December 31, 2008 <?php $string = <<<XML <a xmlns:b> <foo name="one" game="lonely">1</foo> </a> XML; $xml = simplexml_load_string($string); foreach($xml->foo[0]->attributes() as $a => $b) { echo $a,'="',$b,"\"\n"; } ?> From http://us2.php.net/manual/en/function.simplexml-element-attributes.php Quote Link to comment https://forums.phpfreaks.com/topic/138946-solved-how-to-call-this-with-simplexml_load/#findComment-727010 Share on other sites More sharing options...
Graxeon Posted December 31, 2008 Author Share Posted December 31, 2008 I'm sorry...but can you use that code with the example that I gave, please? I'm a little confused >.< Quote Link to comment https://forums.phpfreaks.com/topic/138946-solved-how-to-call-this-with-simplexml_load/#findComment-727077 Share on other sites More sharing options...
premiso Posted December 31, 2008 Share Posted December 31, 2008 <?php $string = <<<XML <rss version="2.0"> <channel> <title>Desc</title> <link auto="false" guide="false" timer="1s" path="google" /> </channel> </rss> XML; $sxml = new SimpleXmlElement($string); echo getAttribute("path", $sxml->channel[0]->link[0]) . "<br />"; function getAttribute($attName, $sxml) { foreach($sxml->attributes() as $a => $b) { if ($a == "path") return $b; //echo $a,'="',$b,"\"\n"; } return false; } ?> For a tutorial as to say: http://blog.stuartherbert.com/php/2007/01/07/using-simplexml-to-parse-rss-feeds/ Quote Link to comment https://forums.phpfreaks.com/topic/138946-solved-how-to-call-this-with-simplexml_load/#findComment-727095 Share on other sites More sharing options...
Graxeon Posted December 31, 2008 Author Share Posted December 31, 2008 Ok, cool. Umm...can you help me get this script to work? I tried messing around with it but it's no good What I'm trying to do is grab whatever is in "path=" under "_video" from this XML file: http://www.sqweasel.com/flv_player/data/playerConfigEmbed/140.xml **The number "140" can be changed to whatever is in the array <?php $allowed_url = array("8776", //test start "140"); $passed_url = $_GET['url']; //this would be http://www.google.com foreach ($allowed_url as $allowed) { if(stristr($allowed, $passed_url) !== false) { $string = $url='http://www.sqweasel.com/flv_player/data/playerConfigEmbed/'.$_GET['url']; $sxml = new SimpleXmlElement($string); echo($node) getAttribute("path", $sxml->playerConfig[0]->_video[0]) . "<br />"; header('Location: '.$node['url']); exit; } } header("Location: http://www.google.com/"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/138946-solved-how-to-call-this-with-simplexml_load/#findComment-727149 Share on other sites More sharing options...
premiso Posted December 31, 2008 Share Posted December 31, 2008 <?php $allowed_url = array("8776", //test start "140"); $passed_url = $_GET['url']; //this would be http://www.google.com foreach ($allowed_url as $allowed) { if(stristr($allowed, $passed_url) !== false) { $url='http://www.sqweasel.com/flv_player/data/playerConfigEmbed/'.$_GET['url']; $string = file_get_contents($url); $sxml = new SimpleXmlElement($string); $node = getAttribute("path", $sxml->playerConfig[0]->_video[0]) . "<br />"; header('Location: '.$node); exit; } } header("Location: http://www.google.com/"); function getAttribute($attName, $sxml) { foreach($sxml->attributes() as $a => $b) { if ($a == $attName) return $b; } return false; } ?> I am not sure exactly what you are trying to do with "$node" .... that just confused me. Also you were just getting the url and parsing that. use file_get_contents to get the contents of a URL. And why are you redirecting it? That also confused me....Please enlighten us on what exactly you are trying to do and what is your goal for this script? All that weirdness aside, try what I posted above. I believe that will get you what you want. Quote Link to comment https://forums.phpfreaks.com/topic/138946-solved-how-to-call-this-with-simplexml_load/#findComment-727170 Share on other sites More sharing options...
Graxeon Posted December 31, 2008 Author Share Posted December 31, 2008 I'm trying to setup a little "theater" for my Sony PSP. I'm going to be running it from XAMPP or even off of my PSP's memory. Anyways...umm: I got this: Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in file.php:12 Stack trace: #0 file.php(12): SimpleXMLElement->__construct('') #1 {main} thrown in file.php on line 12 Here's a clearer explanation of what I would like the script to do: -I request "file.php?url=140" -"file.php" goes to "http://www.sqweasel.com/flv_player/data/playerConfigEmbed/140.xml" and grabs whatever is in the "path=" of "_video" in that XML file (in this case, it would be the MP3 file). Oh btw...the script needs a "add .xml after the input" -"file.php" then redirects me to that file (so then I can listen to it from my PSP without downloading) If the input isn't in the "allowed URLs" array...then the script redirects the me to "google.com" Does that make more sense? Thanks for taking your time to help me out, btw. P.S. I know...I'm a PSP noob Quote Link to comment https://forums.phpfreaks.com/topic/138946-solved-how-to-call-this-with-simplexml_load/#findComment-727181 Share on other sites More sharing options...
premiso Posted December 31, 2008 Share Posted December 31, 2008 <?php $allowed_url = array("8776", //test start "140"); $passed_url = $_GET['url']; //this would be http://www.google.com foreach ($allowed_url as $allowed) { if(stristr($allowed, $passed_url) !== false) { $url='http://www.sqweasel.com/flv_player/data/playerConfigEmbed/'.$allowed . '.xml'; $string = file_get_contents($url); $sxml = new SimpleXmlElement($string); $node = getAttribute("path", $sxml->playerConfig[0]->_video[0]) . "<br />"; header('Location: '.$node); exit; } } header("Location: http://www.google.com/"); function getAttribute($attName, $sxml) { foreach($sxml->attributes() as $a => $b) { if ($a == $attName) return $b; } return false; } ?> Should get you your results. Quote Link to comment https://forums.phpfreaks.com/topic/138946-solved-how-to-call-this-with-simplexml_load/#findComment-727182 Share on other sites More sharing options...
Graxeon Posted December 31, 2008 Author Share Posted December 31, 2008 I tried the script but I got this: Fatal error: Call to a member function attributes() on a non-object in file.php on line 24 Quote Link to comment https://forums.phpfreaks.com/topic/138946-solved-how-to-call-this-with-simplexml_load/#findComment-727187 Share on other sites More sharing options...
premiso Posted December 31, 2008 Share Posted December 31, 2008 <?php $allowed_url = array("8776", //test start "140"); $passed_url = $_GET['url']; //this would be http://www.google.com foreach ($allowed_url as $allowed) { if(stristr($allowed, $passed_url) !== false) { $url='http://www.sqweasel.com/flv_player/data/playerConfigEmbed/'.$allowed . '.xml'; $string = file_get_contents($url); $sxml = new SimpleXmlElement($string); $node = $sxml->_video[0]->attributes()->path; header('Location: '.$node); exit; } } header("Location: http://www.google.com/"); ?> Didn't need the "playerConfig" portion. Quote Link to comment https://forums.phpfreaks.com/topic/138946-solved-how-to-call-this-with-simplexml_load/#findComment-727215 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.