我试图学习一些代码的使用,并且我试图将信息或某些文本从其他网站废弃到我的网站上(仅供个人使用)。
好吧,例如我想从这个网站获取信息:
http://en.sratim.co.il/tt1150273/ROOM-(2015)/
我试图废除这一年,如:
$year = explode( '<span class="yearpronobold">' , $content );
$year_end = explode("</span>" , $year[1] );
但结果是:
<a href="browse.php?uy=2015&fy=2015">2015</a>
我希望结果只有数字2015
也无法取消演员
演员:William H. Macy,Joan Allen(I),Brie Larson,Cas Anvar, Randal Edwards,Megan Park,Chantelle Chung
它给了我ARAY
答案 0 :(得分:1)
include "simple_html_dom.php";
function doStrips($getString) {
$getString = strip_tags($getString);
return $getString!="" ? $getString : "N/A";
}
$mainUrl= "http://en.sratim.co.il/";
$url = "http://en.sratim.co.il/tt1150273/ROOM-(2015)/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close($ch);
$html = new simple_html_dom();
$html->load($server_output);
$releaseYear = $html->find('.yearpronobold');
$actorDetails = $html->find('a[itemprop="actors"]');
$directorDetails= $html->find('a[itemprop="director"]');
$getDuration = $html->find('time[itemprop="duration"]');
$publishedDate = $html->find('time[itemprop="datePublished"]');
$getGenre = $html->find('span[itemprop="genre"]');
$getImage = $html->find('img[itemprop="image"]');
//print_r($getImage);
echo "Release Year - ".doStrips($releaseYear[0]->children(0))."<br />";
echo "Actor(s) - ".doStrips(implode(", ",$actorDetails))."<br />";
echo "Director - ".doStrips(implode(", ",$directorDetails))."<br />";
echo "Duration - ".doStrips(implode(", ",$getDuration))."<br />";
echo "Published Date - ".doStrips(implode(", ",$publishedDate))."<br />";
echo "Genre - ".doStrips(implode(", ",$getGenre))."<br />";
echo "Image - <img src='".$mainUrl.$getImage[0]->attr["src"]."' /><br />";
首先,您需要检查服务器上是否启用了php_curl
。
关于PHP_CURL
的{{3}}教程。