簡體   English   中英

使用 htmlentities 打印頁面內容不適用於 google.com

[英]print content of page by using htmlentities dont work for google.com

我使用此代碼打印網頁內容(源代碼):

<?php
$url='http://cloob.com';
$ch=curl_init();
$timeout=5;

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
// Get URL content
$lines_string=curl_exec($ch);
// close handle to release resources
curl_close($ch);
var_dump( htmlspecialchars($lines_string));
//echo htmlentities($lines_string);
//var_dump( $lines_string);
?>

這是有效的,但是當我將 URL 更改為https://google.com不起作用,為什么?

當我在兩種情況下直接使用(當我不使用htmlentities() )它都有效......(我使用http://phpfiddle.org/

首先要做的是閱讀文檔

如果輸入字符串在給定的編碼中包含無效的代碼單元序列,則將返回一個空字符串,除非設置了 ENT_IGNORE 或 ENT_SUBSTITUTE 標志。

因此,我們可能在 PHP 解析 HTML 時遇到問題,或者編碼不正確,或者 HTML 不正確。

當您為 google 網站使用正確的編碼時,您會得到您想要的結果:

var_dump( htmlspecialchars($lines_string, ENT_COMPAT, 'ISO-8859-1'));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM