【问题标题】:How do i store Url in a variable and check if its is matchable with another url如何将 Url 存储在变量中并检查它是否与另一个 url 匹配
【发布时间】:2020-12-30 17:42:12
【问题描述】:

我正在对我的网站进行快速更改,但我很少陷入一种情况,我想要的是我想将特定页面的 URL 存储在 $variable 中,并且我想检查存储 $variable url 的天气与我喜欢提供的自定义链接相匹配。

例如,我的标题 url 是 https://jonty/page-1.com,我想存储在 $variable 中,

我还想应用条件来检查天气我的 $variable url 类似于 https://jonty/page-1.com

if($variable == https://jonty/page-1.com) {
      //condition
   }

【问题讨论】:

  • 当前代码会发生什么?这是伪代码吧?
  • 可以使用location.href获取当前url
  • @user3783243 这只是我自己写的测试代码。它不起作用,我很困惑如何将 url 存储在 $variable 中。

标签: php arrays wordpress


【解决方案1】:

您可以通过以下方式获取用户的当前网址:

$variable = $_SERVER['REQUEST_URI'];

所以你可以检查条件是否为真

if($variable == 'https://example.com/test') {
    // Blob Blob Blob
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-12
    • 1970-01-01
    • 1970-01-01
    • 2019-02-23
    • 1970-01-01
    • 2015-08-12
    • 2012-06-02
    相关资源
    最近更新 更多