我有这个功能。函数使用DOMDocument类生成错误。
有人知道为什么吗?谢谢你的帮助
function getTitleAndLinks($content)
{
$doc = new \DOMDocument();
$doc->loadHTML($content);
$links = [];
$container = $doc->getElementById("content");
$arr = $container->getElementsByTagName("a");
foreach($arr as $item)
{
$href = $item->getAttribute("href");
$title = $item->getAttribute("title");
if($item->hasAttribute('rel') && $item->getAttribute('rel') == 'bookmark') {
$links[] = [
'href' => $href,
'title' => $title
];
}
}
return $links;
}我有这样的恐惧:
警告: DOMDocument::loadHTML():空字符串作为第64行/home/pc47230/domains/pc47230.wsbpoz.solidhost.pl/public_html/projektkoncowy/functions/functions.php中的输入提供 致命错误:未捕获错误:调用/home/pc47230/domains/pc47230.wsbpoz.solidhost.pl/public_html/projektkoncowy/functions/functions.php:69堆栈跟踪中null的成员函数getElementsByTagName():#0 /home/pc47230/domains/pc47230.wsbpoz.solidhost.pl/public_html/projektkoncowy/index.php(12):getTitleAndLinks(false) #1 {main}在第69行的/home/pc47230/domains/pc47230.wsbpoz.solidhost.pl/public_html/projektkoncowy/functions/functions.php中抛出
发布于 2019-06-19 13:52:12
我从这个函数中得到了$content:
function curl_get_wp_login( $login_user, $login_pass, $login_url, $visit_url, $http_agent, $cookie_file ){
if( !function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' )){
$m = "cUrl is not vailable in you PHP server.";
echo $m;
}
// Preparing postdata for wordpress login
$data = "log=". $login_user ."&pwd=" . $login_pass . "&wp-submit=Log%20In&redirect_to=" . $visit_url;
// Intialize cURL
$ch = curl_init();
// Url to use
curl_setopt( $ch, CURLOPT_URL, $login_url );
// Set the cookies for the login in a cookie file.
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie_file );
// Set SSL to false
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/CAcerts/sni238399cloudflaresslcom.crt");
// User agent
curl_setopt( $ch, CURLOPT_USERAGENT, $http_agent );
// Maximum time cURL will wait for get response. in seconds
curl_setopt( $ch, CURLOPT_TIMEOUT, 36000 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
// Return or echo the execution
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
// Set Http referer.
curl_setopt( $ch, CURLOPT_REFERER, $login_url );
// Post fields to the login url
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
curl_setopt( $ch, CURLOPT_POST, 1);
// Save the return in a variable
$content = curl_exec ($ch);
/*
** if you need to visit another url ,you can do it here.
** curl_setopt( $ch, CURLOPT_URL, 'a new url address or a file download url' );
** $content = curl_exec ($ch);
*/
// Close the cURL.
curl_close( $ch );
return $content;
}那是假的,我不知道为什么。
https://stackoverflow.com/questions/56668191
复制相似问题