简体   繁体   English

PHP脚本列出超链接?

[英]PHP script to list hyperlinks?

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. 我知道足够多的PHP可以说是危险的。 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. 我想创建一些PHP代码,以捕获目录中的所有页面名称并将其作为超链接输出。 This way I don't have to manually do this every week PLUS update all the old pages with the new link. 这样,我不必每周手动进行此操作,而且还可以使用新链接更新所有旧页面。

THANKS! 谢谢!

You can use the code below and you should edit the $fullPath , $relativePath , $filter and $after Variables. 您可以使用下面的代码,并且应编辑$ fullPath$ relativePath$ filter$ after变量。

$fullPath is your directory's exact path on the computer. $ fullPath是您的目录在计算机上的确切路径。

$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 ) $ relativePath的值应相对于您在其中使用此脚本的页面(您可以在http://bit.ly/fCbRDh上找到有关路径的更多信息)

And $filter 's values are optional. $ filter的值是可选的。 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. $ after也是可选的。 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>\n" . $after;
    }
    closedir($handle);
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM