문제

I'm parsing this rss with php and i'm trying to display the youtube video.In the first item i'm getting an error and the video is not displayed.In the second item the video is displayed normally.
I have to remove 123.gr// from this line :

 <iframe width="780" height="470" src="'http://123.gr///www.youtube.com/embed/WDK5BTuFMRM?rel=0&vq=hd1080" frameborder="0" allowfullscreen></iframe>

I thought that a good idea to do that is to use explode function But i didn't find the way yet.

Take a look in my code :

<?php
            $html = "";
            $url = "123.xml";
            $xml = simplexml_load_file($url);
            for ( $i = 0; $i < 10; $i++ ){
                $title = $xml->channel->item[$i]->title;
                $description = $xml->channel->item[$i]->description;
                print_r(explode('"',$description,5));
?>
        <div data-role="content">
            <div data-role="collapsible" data-theme="b">
                <h3><?php echo $title ?></h3>
                <p><?php echo $description ?></p>
            </div>
        </div>
        <?php   
            }
        ?>

Here's is a sample of the rss

<item>
  <title>This is the title</title>
  <description>
     <![CDATA[Some text
      <p>
      <div align="center">
      <iframe width="780" height="470" src="'http://123.gr///www.youtube.com/embed/WDK5BTuFMRM?rel=0&vq=hd1080" frameborder="0" allowfullscreen></iframe>
      </div>
    ]]>
  </description>
</item>
<item>
  <title>This is the title</title>
  <description>
    <![CDATA[Some text
        <p>
        <div align="center">
        <iframe width="780" height="470" src="'http://www.youtube.com/embed/WDK5BTuFMRM?rel=0&vq=hd1080" frameborder="0" allowfullscreen></iframe>
        </div>
      ]]>
   </description>
 </item>

Any help will be appreciated

도움이 되었습니까?

해결책 2

Finnally i use the str_replace and displays both videos.Here's is my code , maybe will help someone in the future

<?php
        $html = "";
        $url = "http://123.gr/index.php?format=feed&type=rss";
              $xml = file_get_contents($url);
          $x = new SimpleXmlElement($xml);


          foreach ( $x->channel->item as $entry ){
              $part_to_replace   = array("http://123.gr///www.youtube.com/");
              $replaced   = array("http://www.youtube.com/");
              $entry->description = str_replace( $part_to_replace, $replaced, $entry->description );
              echo $entry->description;
                  echo $entry->title;     
        ?>

다른 팁

You could use something like this to get all youtube links:

$xml = file_get_contents($url);
preg_match_all('[(?P<link>www\.youtube\.com.*?)"]', $xml, $matches);
var_dump($matches);

This will give you an array in $matches which contains all links to youtube videos found in your rss xml.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top