0

试图从当前页面中提取一个 href 路径(#navbar a href 以 $pg 结尾)。

在第一个 foreach 上收到警告:

file_get_contents() [function.file-get-contents]: Filename cannot be empty.

我怎样才能解决这个问题?

<?php
include_once 'path/to/simple_html_dom.php';

$pg = 'c.html';
echo 'Page: ' . $pg . "<br />"; // Correct: c.html
$cpath = $_SERVER['REQUEST_URI'];
echo var_dump($cpath).": Current Path"."<br />";  // Correct: /copyr/index.php
$cfile = basename($cpath);
echo 'Current File: ' . $cfile . "<br />";  // Correct: index.php
$html = file_get_html($cfile);

foreach($html->find(sprintf('#navbar a[href=%s]', $pg)) as $path) {  // BROKEN
    echo 'Path: ' . $path."<br />";
    $tpath = $path."/".$pg;
    echo 'Total Path: ' . $tpath;
    $html->clear();
}

$html = file_get_html($tpath);

foreach($html->find('#testdiv2') as $ret) {
  echo $ret;
  $html->clear();
}

?>
4

1 回答 1

2

basename返回路径的最后一部分。如果REQUEST_URI/(结尾http://yourdomain.arg/,则 basename 返回一个空字符串,而file_get_html需要一个 uri 或文件名。

于 2012-10-16T20:19:42.197 回答