当前位置: 首页>>代码示例>>PHP>>正文


PHP Http::Request方法代码示例

本文整理汇总了PHP中Http::Request方法的典型用法代码示例。如果您正苦于以下问题:PHP Http::Request方法的具体用法?PHP Http::Request怎么用?PHP Http::Request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Http的用法示例。


在下文中一共展示了Http::Request方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct($url)
 {
     if (!preg_match('!^https?://!i', $url)) {
         $url = 'http://' . $url;
     }
     $data = Http::Request($url);
     //$enc = mb_detect_encoding($str, "UTF-8,ISO-8859-1,ASCII");
     $html = mb_convert_encoding($data, "UTF-8", "UTF-8,ISO-8859-1,ASCII");
     //$html = utf8_encode($html);
     $r = new Readability($html, $url);
     $r->init();
     if (!isset($this->metadata["title"])) {
         $this->metadata["title"] = CharacterEntities::convert(strip_tags($r->getTitle()->innerHTML));
     }
     if (!isset($this->metadata["author"])) {
         $parts = parse_url($url);
         $this->metadata["author"] = $parts["host"];
     }
     $article = $r->getContent()->innerHTML;
     if (substr($article, 0, 5) == "<body") {
         $article = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/></head>" . $article . "</html>";
     } else {
         $article = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/></head><body>" . $article . "</body></html>";
     }
     $doc = new DOMDocument();
     @$doc->loadHTML($article) or die($article);
     $doc->normalizeDocument();
     $this->images = $this->handleImages($doc, $url);
     $this->text = $doc->saveHTML();
 }
开发者ID:master3395,项目名称:CBPPlatform,代码行数:30,代码来源:OnlineArticle.php

示例2: DownloadImage

 /**
  * Download an image.
  *
  * @param string $url Url to the image
  *
  * @return false|string False if failed, else the data of the image (converted to grayscale jpeg)
  */
 public static function DownloadImage($url)
 {
     $data = Http::Request($url);
     $imgFile = @imagecreatefromstring($data);
     if ($imgFile !== false) {
         $result = self::CreateImage($imgFile);
         imagedestroy($imgFile);
         return $result;
     }
     return false;
 }
开发者ID:wallabag,项目名称:php-mobi,代码行数:18,代码来源:ImageHandler.php

示例3: addChapter

 private function addChapter($n)
 {
     $doc = new DOMDocument();
     $file = Http::Request(self::$prefix . $this->id . "/" . $n . "/");
     @$doc->loadHTML($file) or die($file);
     if (!$this->downloadedMetadata) {
         $this->loadMetadata($doc);
         $this->downloadedMetadata = true;
     }
     if ($this->chapterCount < 0) {
         $this->chapterCount = $this->getNumberChapters($doc);
         if ($this->chapterCount > 4) {
             die("Too many files to download, don't use php for this!");
         }
     }
     $textEl = $doc->getElementById("storytext");
     if ($textEl == null) {
         die("Error: " . $doc->saveHTML());
     }
     $horizontalRulebars = $doc->getElementsByTagName('hr');
     /**
      * @var DOMNode
      */
     $hr;
     foreach ($horizontalRulebars as $hr) {
         $hr->setAttribute("size", null);
         $hr->setAttribute("noshade", null);
     }
     $text = $this->innerHtml($textEl);
     $title = "";
     $selects = $doc->getElementsByTagName('select');
     foreach ($selects as $select) {
         if ($select->hasAttribute("name") && $select->getAttribute("name") == "chapter") {
             $options = $select->getElementsByTagName("option");
             $test = $n . ". ";
             foreach ($options as $option) {
                 $val = $option->nodeValue;
                 if (substr($val, 0, strlen($test)) == $test) {
                     $title = substr($val, strlen($test));
                     break;
                 }
             }
             break;
         }
     }
     $this->addPage($text, $title);
 }
开发者ID:master3395,项目名称:CBPPlatform,代码行数:47,代码来源:FanFictionNet.php

示例4: downloadImages

 /**
  * @param DOMElement $dom
  *
  * @return array
  */
 private function downloadImages($links)
 {
     $images = array();
     foreach ($links as $link) {
         $imgFile = @imagecreatefromstring(Http::Request($link));
         if ($imgFile === false) {
             $imgFile = @imagecreate(1, 1);
             $black = @imagecolorallocate($imgFile, 255, 255, 255);
         }
         if ($imgFile !== false) {
             @imagefilter($imgFile, IMG_FILTER_GRAYSCALE);
             ob_start();
             @imagejpeg($imgFile);
             $image = ob_get_contents();
             ob_end_clean();
             $images[$this->imgCounter] = new FileRecord(new Record($image));
             imagedestroy($imgFile);
             ++$this->imgCounter;
         }
     }
     return $images;
 }
开发者ID:wallabag,项目名称:php-mobi,代码行数:27,代码来源:PreprocessedArticle.php


注:本文中的Http::Request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。