LoginSignup
2
1

More than 1 year has passed since last update.

PHP8 で phpQuery を使う

Last updated at Posted at 2021-08-21

すぐ出るエラー おそらくPHP7以上 の対応

Compile Error - Array and string offset access syntax with curly braces is no longer supported in APPPATH/vendor/phpQuery-onefile.php on line 2156

エラーの通りソースコードを修正
2156行と2171行のエラーを修正 {数値} を [数値] へ
修正前

// 2156行
if ($param{0} == 'n')

// 2171行
else if (mb_strlen($param) > 1 && $param{1} == 'n')

修正後

// 2156行
if ($param[0] == 'n')

// 2171行
else if (mb_strlen($param) > 1 && $param[1] == 'n')

この後に出るエラー

修正してもこういうエラーが出ます。

phpQuery-onefile.php(327): DOMDocument->loadHTML()
phpQuery-onefile.php(244): DOMDocumentWrapper->loadMarkupHTML()
phpQuery-onefile.php(191): DOMDocumentWrapper->loadMarkup()
phpQuery-onefile.php(177): DOMDocumentWrapper->load()
phpQuery-onefile.php(4857): DOMDocumentWrapper->__construct()
phpQuery-onefile.php(4631): phpQuery::createDocumentWrapper()

この対策はこう。 phpQuery::newDocumentの前後にこんな記述を入れます。

$url = "https://xxxx.com";
$html = file_get_contents($url);

libxml_use_internal_errors( true );  // 追加
$html = \phpQuery::newDocument($html);
libxml_clear_errors();  // 追加

これで phpQuery が利用できます。

2
1
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
2
1