$refPointer = $site_to_be_extracted . $a->href;
echo $refPointer . '<br>';
在输出中生成(Chrome浏览器):
http://www.hackingwithphp.com/1/1/0/is-this-book-for-you
您希望以下行生成正确的<a>
标记。这是一个正确的链接
print '<a href=' . $refPointer . '>' . $a . '</a>';
而是在输出中生成:
localhost/1/1/0/is-this-book-for-you
因此协议(HTTP)和 $ site_to_be_extracted (www.hackingwithphp.com)都将丢失。并替换为&#34; localhost&#34;
为什么?可能是什么问题
这是它发生的全部功能。现在它工作正常
include('simple_html_dom.php');
.
.
function createChapterContent ($site_to_be_extracted, $chapter_to_be_extracted) {
$html = file_get_html($chapter_to_be_extracted);
$refPointer;
foreach($html->find('ol') as $ol) {
foreach($ol->find('li') as $li) {
// echo '<br>' . $li->innertext ;
foreach($li->find('a') as $a) {
// Original. Causing the reported problem
// $refPointer = $site_to_be_extracted . $a->href;
// echo $refPointer . '<br>';
// changed to (see below). Now the output is correct
// Why?
$a->href = $site_to_be_extracted . $a->href;
$refPointer = $a->href;
print '<a href=' . $refPointer . '>' . $li->innertext . '</a>' . '<br>';
break;
};
}
}