导航栏

本文介绍了一种基于URL地址进行前后页切换的方法,通过解析URL获取当前页面信息,并实现上一页与下一页的功能。该方法虽然简单直接,但在实际应用中灵活性有限。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 <?

//http://www.yourmom.com/dinner/tuna_1.html
$full_path=getenv("REQUEST_URI");  
$root=dirname($full_path);                 //  /dinner/
$page_file = basename($full_path);        //  tuna_1.html
$page_num = substr($page_file  , strrpos($page_file, "_") + 1  , strpos($page_file, ".html") - (strrpos($page_file, "_") + 1)  );    //  1
$partial_path = substr($page_file, 0, strrpos($page_file, ".")); //   dinner/tuna_1
$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=$root/$prev_page_file> previous </a>"; 
 if ($next_exists)  {
     print " | "; 
 }

if ($next_exists)  { 
   print "<a href=$root/$next_page_file>next</a>";
}  

?>

缺陷:只能按页码来,实用性不强。但可学习如何去url地址

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值