dtntjwkl83750 2011-02-02 03:13
浏览 17

PHP脚本列出超链接?

I have a website that handles streamed content. With the general nature of the site though we generally have to update it weekly. This means adding a new page every week for each new streaming episode.

I know enough PHP to be dangerous so to speak. I store each new webpage in a folder. The folder is appropriately titled the name of the streaming series. I want to create some PHP code that grabs all the pages names in the directory and outputs them as hyperlinks. This way I don't have to manually do this every week PLUS update all the old pages with the new link.

THANKS!

  • 写回答

1条回答 默认 最新

  • dsjbest2015 2011-02-02 04:00
    关注

    You can use the code below and you should edit the $fullPath, $relativePath, $filter and $after Variables.

    $fullPath is your directory's exact path on the computer.

    $relativePath's value should be relative to your page which you're using this script in it (you can find more info about paths here http://bit.ly/fCbRDh)

    And $filter's values are optional. You can add or edit respectively as i do. It's for filtering links extensions or much more, so your document extensions will not be on your page link's texts.

    $after is optional too. It's creating new line after the links right now, you can change it to whatever you want.

    <?php
    $fullPath = 'C:/ROOT/project/';
    $relativePath = '../pages/';
    $filter = array('.html', '.htm', '.php');
    $after = '<br />';
    
    if ($handle = opendir($fullPath)) {
        while (false !== ($file = readdir($handle))) {
            $href = $relativePath . $file;
            echo '<a href="' . $href . '">' . str_replace($filter, '', $file) . "</a>
    " . $after;
        }
        closedir($handle);
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大