All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
分析:中文搜索引擎百度排名初步观察_JavaScript技术_编程技术
c#判断数据NULL值的方法_[Asp.Net教程]
C#中的常用的数学术语
解决,ASP.NET,中目录访问权限的问题_[Asp.Net教程]
asp.net身份验证(登录控件),基于标准的sqlserver_[Asp.Net教程]
用户需要怎样的网站设计_研究探讨_seo学堂
基于PHP和AJAX创建RSS聚合器_[PHP教程]
注册COM+服务组件
基于.Net的SAP,Portal开发_[Asp.Net教程]
PHP学习宝典-第八章(二)_[PHP教程]
Reading number is top 10 pictures
girl of HuNan name is LiXiang(湖南辣姐李湘的写真)
修电脑也有这么漂亮的美女
BingBingFan apple dew point photo gallery2
八个盛产美女的国家1
A beautiful girl to bud3
八个盛产美女的国家2
开始让人感动,后来......
Startling Russian girl blind date scene2
采访美女孙菲菲
The money of more than 100 countries and regions16
Download software ranking
圣殿祭司的ASP.NET.2.0.开发详解-使用C#
Sora aoi 120 minutes
Boxer vs Yellow2
Tram sex maniac 2 (H) rar bag5
Tram sex maniac 2 (H) rar bag15
Sora aoi's film--cangkong_Blue.Sky
C语言教程TXT
VC++6.0简体中文版
传奇私服架设教程
jdk1.5
delv published in(发表于) 2013/12/29 4:45:28 Edit(编辑)
怎样用PHP来给网页做导航栏_php资料_编程技术

怎样用PHP来给网页做导航栏_php资料_编程技术

怎样用PHP来给网页做导航栏_php资料_编程技术-你的首页-uuhomepage.com

译者注:本文原名《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, "_"));

上一篇:在PHP中开发XML应用程..v_page_file = $partial_path . "_" . (string)($page_num-1) . ".html";$next_page_file = $partial_path . "_" . (string)($page_num+1) . ".html";

上一篇:在PHP中开发XML应用程..v_exists = file_exists(上一篇:在PHP中开发XML应用程..v_page_file);$next_exists = file_exists($next_page_file);

if (上一篇:在PHP中开发XML应用程..v_exists)

{ print "previous";if ($next_exists)

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

{ print "next";}

?>//原程序完。

代码分析:OK! 前面做了足够的铺垫工作,现在让我们来看看如何来用PHP来完成这项工作:

<!—— 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);

/* PHP函数getenv()用来取得环境变量的值,REQUEST_URI的值是紧跟在主机名后的部分URL,假如URL是http://www.yourmom.com/dinner/tuna_1.html, 那它的值就为/dinner/tuna_1.html. 现在我们将得到的那部分URL放在变量$full_path中,再用dirname()函数来从URL中抓取文件目录,用basename()函数取得文件名,用上面的例子来讲dirname()返回值:/dinner/;basename()返回:tuna_1.html.接下来的部分相对有些技巧,假如我们的文件名以story_x的格式命名,其中x代表页码,我们需要从中将我们使用的页码抽出来。当然文件名不一定只有一位数字的模式或只有一个下划线,它可以是tuna_2.html,同样它还可以叫做tuna_234.html甚至是candy_apple_3.html,而我们真正想要的就是位于最后一个“_”和“。html”之间的东东。可采用如下方法:*/ $page_num = substr($page_file, strrpos($page_file, "_") + 1, strpos($page_file, ".html") - (strrpos($page_file, "_") + 1));/* substr($string, $start,[$length] )函数给了我们字符串$string中从$start开始、长为$length或到末尾的字串(方括号中的参数是可选项,如果省略$length,substr就会返回给我们从$start开始直到字符串末尾的字符串),正如每一个优秀的C程序员告诉你的那样,代表字符串开始的位置开始的数字是“0”而不是“1”。

函数strrpos($string, $what)告诉我们字符串$what在变量$string中最后一次出现的位置,我们可以通过它找出文件名中最后一个下划线的位置在哪,同理,接着的strpos($string, $what)告诉我们“。html”首次出现的位置。我们通过运用这三个函数取得在最后一个“_”和“。html”之间的数字(代码中的strpos()+1代表越过“_”自己)。

剩下的部分很简单,首先为上页和下页构造文件名:*/ $partial_path = substr($page_file, 0, strrpos($page_file, "_"));

上一篇:在PHP中开发XML应用程..v_page_file = $partial_path . "_" . (string)($page_num-1) . ".html";$next_page_file = $partial_path . "_" . (string)($page_num+1) . ".html";

/*(string)($page_num+1)将数学运算$page_num+1的结果转化为字符串类型,这样就可以用来与其他字串最终连接成为我们需要的文件名。

*/ /*现在检查文件是否存在(这段代码假设所有的文件都位于同样的目录下),并最终给出构成页面导航栏的HTML代码。

*/ 上一篇:在PHP中开发XML应用程..v_exists = file_exists(上一篇:在PHP中开发XML应用程..v_page_file);$next_exists = file_exists($next_page_file);

if (上一篇:在PHP中开发XML应用程..v_exists)

{ print "previous";if ($next_exists)

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

{ print "next";}

?>





添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.