【问题标题】:How to Add background or change text如何添加背景或更改文本
【发布时间】:2012-03-03 23:51:11
【问题描述】:

我的目标是创建页面,其中包含有关电影所需的信息以及重定向到您将观看它的视频主机的链接。我找到了一个 IMDB php 插件,我正在尝试将其插入 jquery mobile,以便移动用户可以轻松找到电影并将其流式传输到他们的 iDevice 或任何支持 MP4 格式的设备上。接近http://freeflix.technoinsidr.com/watch.php?m=tt1190080

我已经制作了这个http://ivids.tk/test.php?m=tt0068646 如果可以使用 jquery mobile 作为设计,我如何删除 TITLE、YEAR(所有粗体字)并将 TITLE 与 YEAR 放在同一行?有没有可能?

<?php

class Imdb
{   
    function getMovieInfo($title)
    {
        $imdbId = $this->getIMDbIdFromGoogle(trim($title));
        if($imdbId === NULL){
            $arr = array();
            $arr['error'] = "No Title found in Search Results!";
            return $arr;
        }
        return $this->getMovieInfoById($imdbId);
    }

    function getMovieInfoById($imdbId)
    {
        $arr = array();
        $imdbUrl = "http://www.imdb.com/title/" . trim($imdbId) . "/";
        $html = $this->geturl($imdbUrl);
        if(stripos($html, "<meta name=\"application-name\" content=\"IMDb\" />") !== false){
            $arr = $this->scrapMovieInfo($html);
            $arr['imdb_url'] = $imdbUrl;
        } else {
            $arr['error'] = "No Title found on IMDb!";
        }
        return $arr;
    }

    function getIMDbIdFromGoogle($title){
        $url = "http://www.google.com/search?q=imdb+" . rawurlencode($title);
        $html = $this->geturl($url);
        $ids = $this->match_all('/<a href="http:\/\/www.imdb.com\/title\/(tt\d+).*?".*?>.*?<\/a>/ms', $html, 1);
        if (!isset($ids[0])) //if Google fails
            return $this->getIMDbIdFromBing($title); //search using Bing
        else
            return $ids[0]; //return first IMDb result
    }

    function getIMDbIdFromBing($title){
        $url = "http://www.bing.com/search?q=imdb+" . rawurlencode($title);
        $html = $this->geturl($url);
        $ids = $this->match_all('/<a href="http:\/\/www.imdb.com\/title\/(tt\d+).*?".*?>.*?<\/a>/ms', $html, 1);
        if (!isset($ids[0]))
            return NULL;
        else
            return $ids[0]; //return first IMDb result
    }

    // Scan movie meta data from IMDb page
    function scrapMovieInfo($html)
    {
        $arr = array();
        $arr['title'] = trim($this->match('/<title>(IMDb \- )*(.*?) \(.*?<\/title>/ms', $html, 2));
        $arr['year'] = trim($this->match('/<title>.*?\(.*?(\d{4}).*?\).*?<\/title>/ms', $html, 1));
        $arr['rating'] = $this->match('/ratingValue">(\d.\d)</ms', $html, 1);
        $arr['genres'] = array();
        foreach($this->match_all('/<a.*?>(.*?)<\/a>/ms', $this->match('/Genre.?:(.*?)(<\/div>|See more)/ms', $html, 1), 1) as $m)
            array_push($arr['genres'], $m);

        //Get extra inforation on  Release Dates and AKA Titles
        if($arr['title_id'] != ""){
            $releaseinfoHtml = $this->geturl("http://www.imdb.com/title/" . $arr['title_id'] . "/releaseinfo");
            $arr['also_known_as'] = $this->getAkaTitles($releaseinfoHtml, $usa_title);
            $arr['usa_title'] = $usa_title;
            $arr['release_date'] = $this->match('/Release Date:<\/h4>.*?([0-9][0-9]? (January|February|March|April|May|June|July|August|September|October|November|December) (19|20)[0-9][0-9]).*?(\(|<span)/ms', $html, 1);
            $arr['release_dates'] = $this->getReleaseDates($releaseinfoHtml);
        }
        $arr['plot'] = trim(strip_tags($this->match('/<p itemprop="description">(.*?)(<\/p>|<a)/ms', $html, 1)));
        $arr['poster'] = $this->match('/img_primary">.*?<img src="(.*?)".*?<\/td>/ms', $html, 1);

        $arr['poster_small'] = "";
        if ($arr['poster'] != '' && strrpos($arr['poster'], "nopicture") === false && strrpos($arr['poster'], "ad.doubleclick") === false) { //Get large and small posters
            $arr['poster_small'] = preg_replace('/_V1\..*?.jpg/ms', "_V1._SY150.jpg", $arr['poster']);
        } else {
            $arr['poster'] = "";
        }
        $arr['runtime'] = trim($this->match('/Runtime:<\/h4>.*?(\d+) min.*?<\/div>/ms', $html, 1));
        if($arr['runtime'] == '') $arr['runtime'] = trim($this->match('/infobar.*?(\d+) min.*?<\/div>/ms', $html, 1));
        $arr['storyline'] = trim(strip_tags($this->match('/Storyline<\/h2>(.*?)(<em|<\/p>|<span)/ms', $html, 1)));

        $arr['language'] = array();
        foreach($this->match_all('/<a.*?>(.*?)<\/a>/ms', $this->match('/Language.?:(.*?)(<\/div>|>.?and )/ms', $html, 1), 1) as $m)
            array_push($arr['language'], trim($m));
        $arr['country'] = array();
        foreach($this->match_all('/<a.*?>(.*?)<\/a>/ms', $this->match('/Country:(.*?)(<\/div>|>.?and )/ms', $html, 1), 1) as $c)
            array_push($arr['country'], $c);

        if($arr['title_id'] != "") $arr['media_images'] = $this->getMediaImages($arr['title_id']);

        return $arr;
    }

    // Scan all Release Dates
    function getReleaseDates($html){
        $releaseDates = array();
        foreach($this->match_all('/<tr>(.*?)<\/tr>/ms', $this->match('/Date<\/th><\/tr>(.*?)<\/table>/ms', $html, 1), 1) as $r)
        {
            $country = trim(strip_tags($this->match('/<td><b>(.*?)<\/b><\/td>/ms', $r, 1)));
            $date = trim(strip_tags($this->match('/<td align="right">(.*?)<\/td>/ms', $r, 1)));
            array_push($releaseDates, $country . " = " . $date);
        }
        return $releaseDates;
    }

    // Scan all AKA Titles
    function getAkaTitles($html, &$usa_title){
        $akaTitles = array();
        foreach($this->match_all('/<tr>(.*?)<\/tr>/msi', $this->match('/Also Known As(.*?)<\/table>/ms', $html, 1), 1) as $m)
        {
            $akaTitleMatch = $this->match_all('/<td>(.*?)<\/td>/ms', $m, 1);
            $akaTitle = trim($akaTitleMatch[0]);
            $akaCountry = trim($akaTitleMatch[1]);
            array_push($akaTitles, $akaTitle . " = " . $akaCountry);
            if ($akaCountry != '' && strrpos(strtolower($akaCountry), "usa") !== false) $usa_title = $akaTitle;
        }
        return $akaTitles;
    }

    // Collect all Media Images
    function getMediaImages($titleId){
        $url  = "http://www.imdb.com/title/" . $titleId . "/mediaindex";
        $html = $this->geturl($url);
        $media = array();
        $media = array_merge($media, $this->scanMediaImages($html));
        foreach($this->match_all('/<a href="\?page=(.*?)">/ms', $this->match('/<span style="padding: 0 1em;">(.*?)<\/span>/ms', $html, 1), 1) as $p)
        {
            $html = $this->geturl($url . "?page=" . $p);
            $media = array_merge($media, $this->scanMediaImages($html));
        }
        return $media;
    }

    // Scan all media images
    function scanMediaImages($html){
        $pics = array();
        foreach($this->match_all('/src="(.*?)"/ms', $this->match('/<div class="thumb_list" style="font-size: 0px;">(.*?)<\/div>/ms', $html, 1), 1) as $i)
        {
            array_push($pics, preg_replace('/_V1\..*?.jpg/ms', "_V1._SY0.jpg", $i));
        }
        return $pics;
    }

    // ************************[ Extra Functions ]******************************
    function geturl($url)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        $ip=rand(0,255).'.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip"));
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/".rand(3,5).".".rand(0,3)." (Windows NT ".rand(3,5).".".rand(0,2)."; rv:2.0.1) Gecko/20100101 Firefox/".rand(3,5).".0.1");
        $html = curl_exec($ch);
        curl_close($ch);
        return $html;
    }

    function match_all($regex, $str, $i = 0)
    {
        if(preg_match_all($regex, $str, $matches) === false)
            return false;
        else
            return $matches[$i];
    }

    function match($regex, $str, $i = 0)
    {
        if(preg_match($regex, $str, $match) == 1)
            return $match[$i];
        else
            return false;
    }
}
?>

【问题讨论】:

  • 请再次查看tinyurl.com/so-hintsHow To Ask
  • 完成了。我编辑问题。
  • 太多的问题,是的,这可能是可能的,但我认为人们不会解决这个问题,因为你是新手,你的问题看起来更像是要求,你的代码只是一个丑陋的复制/粘贴。如果您希望人们研究解决方案,您需要在这个问题上做更多的工作......
  • 我不明白你的最终目标是什么。让我们更深入地了解您到底想要做什么,因为这听起来像是一个 JS 屏幕抓取工具,这是在浪费时间。

标签: php jquery css mobile


【解决方案1】:

这确实不应该在 jQuery 中完成,您仍然可以使用一些课程来明确您要查找的内容,但是问题就是问题,这是我的答案:

$('th').hide();
var $titlerow = $('tr td:first'), 
    $yearrow = $('tr:eq(1) td:first'),
    title = $titlerow.text(),
    year = $yearrow.text();

$titlerow.text(title + ' - ' + year);
$yearrow.remove();

注意事项:

  • 不应该这样做是 jQuery。您应该重新排列您的 PHP。如果代码是复制/粘贴的,那么我建议通读它。老实说,我没有阅读您发布的任何内容,因为在您提供链接后,它与客户端问题无关。
  • 应该确保在您的网站中包含 jQuery。它不在您链接到的页面上。否则,我提供的代码将不起作用。
  • 应该将上述代码放入准备好的文档中。我留下了最后一点有点混淆。原因是,如果您不了解此要点,可以通过谷歌搜索其中的术语对您有好处。

【讨论】:

  • 我写了我的目标和我想要做的事情,我会尝试你的代码,但我不确定它是否会工作,因为我得到的信息是使用 IMDB 链接和来自 imdb它需要标题和年份等等。
  • O:谢谢,但我不知道该把代码放在哪里。你有没有想过可以做这样的事情 freeflix.technoinsidr.com/watch.php?m=tt1190080 ?使用我正在使用的代码?
  • 在你的 jsfiddle 它的 HTML 中,每当我在 HTML 中复制 php 代码时,它根本不起作用。
  • 您希望完成的工作将永远无法使用复制/粘贴代码。您必须首先实际学习您正在使用的语言。期间。
  • 同意。谢谢你替我说,@Chad。我想我不会说得这么好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多