开发者

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. 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 page开发者_Go百科s with the new link.

THANKS!


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>\n" . $after;
    }
    closedir($handle);
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜