Jump to content

Recommended Posts

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>

<?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

<?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/

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/");

?>

<?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.

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 :(

<?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.

<?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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.