dqx76962 2012-10-16 20:11
浏览 69

从当前页面获取特定的href

Trying to extract an href path (#navbar a href that ends in $pg) from the current page.

Getting a warning on the first foreach:

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

How can I fix this?

<?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();
}

?>
  • 写回答

1条回答 默认 最新

  • dongxin1999 2012-10-16 20:19
    关注

    basename returns the last part of a path. If REQUEST_URI ends in a / (as in http://yourdomain.arg/, basename returns an empty string, while file_get_html expects an uri or file name.

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀