下記は、youtubeの自分のチャンネルの最新動画を表示させるソースです。
これをサーバにアップするとなぜかウェブサイト上にPHPの一部が表示されて、動画が再生できず。
エラーが発生しましたと動画に表示されてしまいます。
解決策をアドバイス頂けると幸いです。
参考にしたサイト:https://sakic.jp/blog/web/latest-youtube-channel
<!-- box3 --> <article class="box3"> <p><img src="img/title3.png" width="330" height="138" alt="youtube"></p> <div class="box_txt"> <?php $url = "https://www.youtube.com/feeds/videos.xml?channel_id=UC-xxxxxxxxxxxxxxxxx"; $rss = file_get_contents($url); $rss = preg_replace("/<([^>]+?):(.+?)>/", "<$1_$2>", $rss); $rss = simplexml_load_string($rss,'SimpleXMLElement',LIBXML_NOCDATA); foreach($rss->entry as $value): ?> <iframe width="322" height="247" src="https://www.youtube.com/embed/<?php echo htmlspecialchars($value->yt_videoId, ENT_QUOTES, 'UTF-8') ?>" frameborder="0" allowfullscreen></iframe> <?php break; endforeach; ?> </div> </article>
「ソース全体」
<?php require('./news/wp-load.php'); ?> <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <link rel="stylesheet" type="text/css" href="css/top_style.css"> <script src="js/jquery-3.2.1.min.js"></script> <title>aaaaaaaa</title> </head> <body> <!-- main_box --> <section id="main_box" class="clearfix"> <!-- box1 --> <article class="box1"> <p><img src="img/title1.png" width="560" height="138" alt="ピックアップ"></p> <div class="box_txt"> <p><img src="img/p.jpg" width="560" height="250" alt="ピックアップ画像"></p> </div> </article> <!-- box1 --> <!-- box3 --> <article class="box3"> <p><img src="img/title3.png" width="330" height="138" alt="youtube"></p> <div class="box_txt"> <?php $url = "https://www.youtube.com/feeds/videos.xml?channel_id=UC-1QaEudvHG6K8iZOOQmWEQ"; $rss = file_get_contents($url); $rss = preg_replace("/<([^>]+?):(.+?)>/", "<$1_$2>", $rss); $rss = simplexml_load_string($rss,'SimpleXMLElement',LIBXML_NOCDATA); foreach($rss->entry as $value): ?> <?php print($rss); ?> <iframe width="322" height="247" src="https://www.youtube.com/embed/<?php echo htmlspecialchars($value->yt_videoId, ENT_QUOTES, 'UTF-8') ?>" frameborder="0" allowfullscreen></iframe> <?php break; endforeach; ?> </div> </article> <!-- box3 --> </section> <!-- main_box --> <!-- sub_box --> <section id="sub_box" class="clearfix"> <!-- box2 --> <article class="box2"> <p><img src="img/title2.png" width="560" height="138" alt="ニュース"></p> <div class="box_txt"> <ul class="wp"> <?php $posts = get_posts("numberposts=5&category=3&orderby=post_date&offset=0"); foreach ($posts as $post): setup_postdata($post); ?> <li> <p> <?php the_time('Y.m.d') ?> :<a href="<?php the_permalink() ?>"> <?php the_title() ?> </a></p> </li> <?php endforeach; ?> </ul> <p class="article_p"><a href="http://aaaaaaaa.jp/news/category/new/">ニュース一覧</a></p> </div> </article> <!-- box2 --> <!-- box4 --> <article class="box4"> <p><img src="img/title4.png" width="330" height="138" alt="ツイッター"></p> <p class="box_txt"><a class="twitter-timeline" width="330px" height="250px" href="https://twitter.com/aaaaaaaaa?ref_src=twsrc%5Etfw">Tweets by aaaaaaaa</a> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></p> </article> <!-- box4 --> </section> <!-- sub_box --> </body> </html>
回答2件
あなたの回答
tips
プレビュー