PHP从数组中旋转url

发布于 2024-12-17 14:39:30 字数 262 浏览 2 评论 0原文

假设您有一个文件,其中包含一个带有时间的数组和如下代码:

{"TIME":"0410","ARRIVAL":"AAA"}
{"TIME":"0600","ARRIVAL":"BBB"}
{"TIME":"0600","ARRIVAL":"CCC"}
{"TIME":"0600","ARRIVAL":"DDD"}

我需要创建一些东西,根据时间使用数组中的代码来旋转 url。时间函数没问题,但我如何使用数组中的代码更改(旋转)页面的 url?

Say you have a file that contains an array with a time and a code like this:

{"TIME":"0410","ARRIVAL":"AAA"}
{"TIME":"0600","ARRIVAL":"BBB"}
{"TIME":"0600","ARRIVAL":"CCC"}
{"TIME":"0600","ARRIVAL":"DDD"}

I need to create something that rotates the url using the code from the array based on the time. The time function is no problem but how would I be changing(rotating) the url of a page with the codes from the array?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆离笙 2024-12-24 14:39:30

我想您想知道如何将用户重定向到不同的网址。
您可以使用 JavaScript 来执行此操作:

window.location = 'http://www.dummyurl.org/phpscript.php?show<?php echo $array[$now];?>

或者使用标准 html 重定向来执行此操作:

<meta http-equiv="refresh" content="30; url=http://www.dummyurl.org/phpscript.php?show=<?php echo $array[$now];?>">

后一个示例中的 content=30 意味着它会在 30 秒后刷新页面以重新执行您的检查功能并更改适当的 URL。

假设您已经构建了检查时差的函数,只需将此代码放在适当的位置即可!

要迭代页面加载时的不同值,您可以使用 [array_search()][1] 并增加输出上的数组键!

$key = array_search($_GET['show'],$array);
if($array[$key+1]) { $loadme = $array[$key+1];}
else { $loadme = $array[0]; }

这样,您可以搜索 URL 中的值,该值会返回该值所在数组的键。然后将该键加一。如果该键不存在,它将再次从第一个位置开始。

<meta http-equiv="refresh" content="30; url=http://www.dummyurl.org/phpscript.php?show=<?php echo $loadme;?>">

I think you want to know how to redirect the user to different urls.
You can either do that with JavaScript:

window.location = 'http://www.dummyurl.org/phpscript.php?show<?php echo $array[$now];?>

or the same with standard html redirect:

<meta http-equiv="refresh" content="30; url=http://www.dummyurl.org/phpscript.php?show=<?php echo $array[$now];?>">

The content=30 in the latter example means that it refreshes the page after 30 seconds to re-execute your check-function and change the URL appropriately.

Assuming you already built that checking function for the time difference, just put this code where it is appropriate!

To iterate through the different values on page load you can use [array_search()][1] and increase the array-key on the output!

$key = array_search($_GET['show'],$array);
if($array[$key+1]) { $loadme = $array[$key+1];}
else { $loadme = $array[0]; }

That way you search for the value in the URL, which returns you the key of the array it is in. Then you increase the key by one. If this key doesn't exist, it'll start on the first position again.

<meta http-equiv="refresh" content="30; url=http://www.dummyurl.org/phpscript.php?show=<?php echo $loadme;?>">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文