您现在的位置: 无忧电子商务网 >> 信息学院 >> 程序开发 >> php >> 正文

怎样用PHP来给网页做导航栏

作者:佚名    信息学院来源:整理    点击数:    更新时间:2008-2-2 我要参与讨论

 

    译者注:本文原名《Site Navigation with PHP》,原文详述了如何用PHP编程来做出效果理想的网页导航条,本文只选译了其中的部分文章,所选取的部分是文章精髓之所在,只要大家能弄懂这部分内容就可以用同样的原理、思想做出我们需要的效果来,希望给读者能起到抛砖引玉的作用。本文只需要读者具备PHP、HTML的初步知识就可以基本读懂了。

    译 文:如大家所知PHP对于用数据库驱动的网站(making database-driven sites)来讲可谓功能强大,可是我们是否可以用它来做点其他事情呢?PHP给了我们所有我们期望的工具:for与while的循环结构、数学运算等等,还可以通过两种方式来引用文件:直接引用或向服务器提出申请。其实何止这些,让我们来看一个如何用它来做导航条的例子:完整的原代码:

<!—— This "<?" is how you indicate the start of a block of PHP code, ——>

<?php # and this "#" makes this a PHP comment.

    $full_path = getenv("REQUEST_URI");

    $root = dirname($full_path);$page_file = basename($full_path);$page_num = substr($page_file, strrpos($page_file, "_") + 1, strpos($page_file, ".html") - (strrpos($page_file, "_") + 1));

    $partial_path = substr($page_file, 0, strrpos($page_file, "_"));

    $prev_page_file = $partial_path . "_" . (string)($page_num-1) . ".html";$next_page_file = $partial_path . "_" . (string)($page_num+1) . ".html";

    $prev_exists = file_exists($prev_page_file);$next_exists = file_exists($next_page_file);

    if ($prev_exists)

    { print "<a href=http://www.webjx.com/htmldata/2006-03-16/"$root/$prev_page_file">previous</a>";if ($next_exists)

    { print " | ";} if ($next_exists)

    { print "<a href="$root/$next_page_file">next</a>";}

    ?>//原程序完。

 &n

[1] [2] [3] 下一页

在google里搜索更多怎样用PHP来给网页做导航栏

Google
Web www.51ec.org
【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
我来说两句 对此文章发表了评论
  昵 称: *必填    ·注册用户·
  评 分: 1分 2分 3分 4分 5分     严禁发表危害国家安全、政治、黄色淫秽等内容的评论,用户需对自己在使用本网站服务过程中的行为承担法律责任。本站管理员有权保留或删除评论内容,评论内容只代表机友个人观点,与本网站立场无关。  
评 论
内 容

 
评论列表 (最新 评论仅限网友观点!)

供求信息




| 设为首页 | 加入收藏 | 关于我们 | 广告服务 | 联系方式 | 友情链接 | 版权申明