我想创建一个名为NEXT的链接,它将确定当前页面然后将其递增1.我有像sample-1.php,sample-2.php,sample-3.php等文件...因此,当我在sample-1上并单击next时,它将转到sample-2,依此类推。 这就是我得到的,我只是混合了我认为有用的代码。
<a id="asdf" href="$filename" onclick="myfunc"> NEXT </a>
<script>
function myfunc(){
<?php
$filename = basename($_SERVER['PHP_SELF']);
list ($name, $ext) = explode['.', $filename);
list ($basename, $index) = explode['-', $name);
$index++;
$filename = $basename.'.'.$index.$ext;
?>}
</script>
有意义吗?
答案 0 :(得分:1)
没有必要使用Javascript,只需PHP:
<?php
$filename = basename($_SERVER['PHP_SELF']);
list ($name, $ext) = explode['.', $filename);
list ($basename, $index) = explode['-', $name);
$index++;
$filename = "$basename-$index.$ext";
echo "<a id='asdf' href='$filename'> NEXT </a>"
答案 1 :(得分:1)
这对我有用。
<?php
$parts = explode('/', $_SERVER['REQUEST_URI']);
$last = end($parts);
$last1 = explode('.', $last);
$last2 = explode('-', $last1[0]);
$cnum = end($last2);
//next number
$filename = $cnum+1;
?>
<a id="asdf" href="$filename" onclick="myfunc"> NEXT </a>