aristide Posted January 6, 2014 Share Posted January 6, 2014 (edited) I need your help! I need to read this xml file... but the problem is that it's not working! This is the XML <rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0"> <channel> <item> <title>Video</title> <media:content url="http://videourl.com/" type="video/x-flv" duration="5128"/> </item> </channel> </rss> And this is my code: <?php $xml=simplexml_load_file("http://videourl.com/etc/"); echo $xml->getName() . "<media:content url="; foreach($xml->children() as $child) { echo $child->getName() . ": " . $child . ""; } ?> And it's not working! It's not working because nothing gets echoed, or printed! Does anyone spot the error? Could it be because the URL of the xml file does not end in with .xml? or is it because this is MRSS xml? thanks! Edited January 6, 2014 by aristide Quote Link to comment Share on other sites More sharing options...
.josh Posted January 6, 2014 Share Posted January 6, 2014 well i made a test file with the xml contents under a different extension and it loads fine, and it also reads fine. using the following: <?php $xml=simplexml_load_file("etc/test.txt"); echo "<pre>";print_r($xml);echo "</pre>"; echo "<b>name: ".$xml->getName(). "</b><br/>"; foreach($xml->children() as $child) { echo "<b>child: ".$child->getName()."</b><br/>"; echo "<pre>";print_r($child); echo "</pre>"; } ?> output: SimpleXMLElement Object ( [@attributes] => Array ( [version] => 2.0 ) [channel] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [title] => Video ) ) ) name: rss child: channel SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [title] => Video ) ) so uh.. problem is probably with whatever the server is responding with, for the url you are using. Try just using file_get_contents and echoing that out to see if you are getting what you expect. Quote Link to comment Share on other sites More sharing options...
aristide Posted January 6, 2014 Author Share Posted January 6, 2014 (edited) Ok i'm going to try. But the thing I'm trying to do is get the URL value in the XML file, not to display the whole file. EDIT: Tried file get contents but it didn't work... I think the website doesn't allow me to read the files? Edited January 6, 2014 by aristide Quote Link to comment Share on other sites More sharing options...
.josh Posted January 6, 2014 Share Posted January 6, 2014 okay well I just used printing out the whole file as an example, roughly same as what you did. Getting a specific value within the file is a separate issue. You first need to sort out getting the file to load. The purpose of using file_get_contents is it's a really basic way of just requesting the file and getting the contents, not worrying about parsing it. If it isn't returning what you expect, then it might provide clues to next step. Quote Link to comment Share on other sites More sharing options...
aristide Posted January 6, 2014 Author Share Posted January 6, 2014 (edited) You are right, the problem is that it's not printing the file at all. Would it help if I gave you the link? here it is: http://www.putlocker.com/get_file.php?stream=WyJSVEU0TnpGRE9ERXlOemt6UTBRek5Eb3hNemc1TlRJMU16VTRMalk1TnpNNk5EVTBZVFpoWTJaak0yWmxOVEJtTVRjNU5UZGhORGxqTWpKbFl6Z3hZbUZtT0dSaU1qVmpPQT09IiwicmVnIl0 And the thing i'm trying to get is the url! is the extension (or the lack of it) blocking me? Edited January 6, 2014 by aristide Quote Link to comment Share on other sites More sharing options...
.josh Posted January 6, 2014 Share Posted January 6, 2014 no, it's not the extension.. php doesn't really care about extensions when it comes to this. Are you sure that's the extent of your code? using file_get_contents() on that url I get the xml contents, and doing it via simplexml works for me (as an xml text to just dump file): <?php $file = "http://www.putlocker.com/get_file.php?stream=WyJSVEU0TnpGRE9ERXlOemt6UTBRek5Eb3hNemc1TlRJMU16VTRMalk1TnpNNk5EVTBZVFpoWTJaak0yWmxOVEJtTVRjNU5UZGhORGxqTWpKbFl6Z3hZbUZtT0dSaU1qVmpPQT09IiwicmVnIl0"; $xml=simplexml_load_file($file); echo "<pre>";print_r($xml);echo "</pre>"; ?> I get: SimpleXMLElement Object ( [@attributes] => Array ( [version] => 2.0 ) [channel] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [title] => Video ) ) ) maybe the server is blocking your sever specifically or something... Quote Link to comment Share on other sites More sharing options...
Barand Posted January 6, 2014 Share Posted January 6, 2014 try $xml=simplexml_load_file("http://www.putlocker.com/get_file.php?stream=WyJSVEU0TnpGRE9ERXlOemt6UTBRek5Eb3hNemc1TlRJMU16VTRMalk1TnpNNk5EVTBZVFpoWTJaak0yWmxOVEJtTVRjNU5UZGhORGxqTWpKbFl6Z3hZbUZtT0dSaU1qVmpPQT09IiwicmVnIl0"); $xml->registerXPathNamespace("media", current($xml->getNamespaces())); foreach ($xml->xpath('//media:content') as $c) { echo $c['url'] . '<br>'; echo $c['type'] . '<br>'; echo $c['duration'] . '<br>'; } Quote Link to comment Share on other sites More sharing options...
aristide Posted January 6, 2014 Author Share Posted January 6, 2014 @barand Thanks for the code but its givin me an error: Warning: simplexml_load_file(http://www.putlocker.com/get_file.php?stream=WyJSVEU0TnpGRE9ERXlOemt6UTBRek5Eb3hNemc1TlRJMU16VTRMalk1TnpNNk5EVTBZVFpoWTJaak0yWmxOVEJtTVRjNU5UZGhORGxqTWpKbFl6Z3hZbUZtT0dSaU1qVmpPQT09IiwicmVnIl0) [function.simplexml-load-file]: failed to open stream: Connection timed out in /home/vol3_2/byethost9.com/b9_14135796/htdocs/test/test.php on line 22 Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://www.putlocker.com/get_file.php?stream=WyJSVEU0TnpGRE9ERXlOemt6UTBRek5Eb3hNemc1TlRJMU16VTRMalk1TnpNNk5EVTBZVFpoWTJaak0yWmxOVEJtTVRjNU5UZGhORGxqTWpKbFl6Z3hZbUZtT0dSaU1qVmpPQT09IiwicmVnIl0" in /home/vol3_2/byethost9.com/b9_14135796/htdocs/test/test.php on line 22 Fatal error: Call to a member function registerXPathNamespace() on a non-object in /home/vol3_2/byethost9.com/b9_14135796/htdocs/test/test.php on line 24 Quote Link to comment Share on other sites More sharing options...
aristide Posted January 6, 2014 Author Share Posted January 6, 2014 no, it's not the extension.. php doesn't really care about extensions when it comes to this. Are you sure that's the extent of your code? using file_get_contents() on that url I get the xml contents, and doing it via simplexml works for me (as an xml text to just dump file): <?php $file = "http://www.putlocker.com/get_file.php?stream=WyJSVEU0TnpGRE9ERXlOemt6UTBRek5Eb3hNemc1TlRJMU16VTRMalk1TnpNNk5EVTBZVFpoWTJaak0yWmxOVEJtTVRjNU5UZGhORGxqTWpKbFl6Z3hZbUZtT0dSaU1qVmpPQT09IiwicmVnIl0"; $xml=simplexml_load_file($file); echo "<pre>";print_r($xml);echo "</pre>"; ?> I get: SimpleXMLElement Object ( [@attributes] => Array ( [version] => 2.0 ) [channel] => SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [title] => Video ) ) ) maybe the server is blocking your sever specifically or something...It must be something... Im pretty sure that my server isnt blocked. I get the result you get aswell, but the thing i need is the url! Quote Link to comment Share on other sites More sharing options...
Barand Posted January 6, 2014 Share Posted January 6, 2014 @barand Thanks for the code but its givin me an error: Warning: simplexml_load_file(http://www.putlocker.com/get_file.php?stream=WyJSVEU0TnpGRE9ERXlOemt6UTBRek5Eb3hNemc1TlRJMU16VTRMalk1TnpNNk5EVTBZVFpoWTJaak0yWmxOVEJtTVRjNU5UZGhORGxqTWpKbFl6Z3hZbUZtT0dSaU1qVmpPQT09IiwicmVnIl0) [function.simplexml-load-file]: failed to open stream: Connection timed out in /home/vol3_2/byethost9.com/b9_14135796/htdocs/test/test.php on line 22 Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://www.putlocker.com/get_file.php?stream=WyJSVEU0TnpGRE9ERXlOemt6UTBRek5Eb3hNemc1TlRJMU16VTRMalk1TnpNNk5EVTBZVFpoWTJaak0yWmxOVEJtTVRjNU5UZGhORGxqTWpKbFl6Z3hZbUZtT0dSaU1qVmpPQT09IiwicmVnIl0" in /home/vol3_2/byethost9.com/b9_14135796/htdocs/test/test.php on line 22 Fatal error: Call to a member function registerXPathNamespace() on a non-object in /home/vol3_2/byethost9.com/b9_14135796/htdocs/test/test.php on line 24 When I ran it it gave http://cdn.putlocker.com/r1KH3Z%2FaMY6kLQ9Y4nVxYpvXrk1%2FQyNvy7xPy8vQTltYliWCdpShxmSPnVzNmP5VlwgLPSYQ%2FddAb5kJ5ZFi3mY0R4gfIY2P69RYRz64ox67Z4LwcyYyZpbQM2FaWb6Or7RgBzqiU1bacFc%2BUyjR95aQgfTpPENEM1NkokFtDaP6oxoBy5mLYlHYbEvIYKwka9qymnoJuwbjKg83fnPX2z7hS6NXWxpudU1NBTWGfSM%3D/aec5ea42616804a307c016b03f6a3e45.flv/aec5ea42616804a307c016b03f6a3e45.flv video/x-flv 5049 Quote Link to comment Share on other sites More sharing options...
Dowlat Posted January 6, 2014 Share Posted January 6, 2014 (edited) What is the issue with file_get_contents, it works fine for me, I have not tried simple xml however, but if its just the URL you need then file_get_contents should be fine. Edited January 6, 2014 by Dowlat Quote Link to comment Share on other sites More sharing options...
Barand Posted January 6, 2014 Share Posted January 6, 2014 try running this code and check "http" is in the list $w = stream_get_wrappers(); echo '<pre>',print_r($w, true),'</pre>'; Quote Link to comment Share on other sites More sharing options...
GetFreaky Posted January 7, 2014 Share Posted January 7, 2014 (edited) It must be something... Im pretty sure that my server isnt blocked. I get the result you get aswell, but the thing i need is the url! I think you need to be more clear, if you get his results then what is the problem? The next step is grabbing the URL, we need to confirm that the xml object returns the content as you mention, so we can move on to getting the URL. Edited January 7, 2014 by GetFreaky Quote Link to comment 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.