LoginSignup
3
0

More than 5 years have passed since last update.

PHP Simple HTML DOM ParserがPHP7.2で動作しない時の対処法

Last updated at Posted at 2018-01-15

環境

  • PHP 7.2.0
  • PHP Simple HTML DOM Parser 1.5.2

現象

以下の結果はfalseになります。

test.php

<?php

require(__DIR__. "/vendor/autoload.php");

$uri = "https://qiita.com/tnm18";
var_dump($html = @Sunra\PhpSimple\HtmlDomParser::file_get_html($uri));

対処法

str_get_html()は問題なく動作するため、最も簡単な対処法は以下のようになります。

test2.php
<?php

require(__DIR__. "/vendor/autoload.php");

$uri = "https://qiita.com/tnm18";
$html_str = @file_get_contents($uri);
var_dump($html = @Sunra\PhpSimple\HtmlDomParser::str_get_html($html_str));

PHP Simple HTML DOM Parserは非常に簡単にDOM操作を行える優れたライブラリですが、ページのサイズが600KBを超えた場合にただfalseを返すだけだったりとエラー処理も非常にシンプルです。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0