【问题标题】:PHP Stripos Check for two Words in a URL stringPHP Stripos 检查 URL 字符串中的两个单词
【发布时间】:2015-08-13 20:32:03
【问题描述】:

我目前正在使用 PHP Stripos OK 来查找 URL 中存在的单词(鹦鹉)。

但是我现在需要检查 URL 中是否存在 2 个单词(green 和 parrots),即它们都必须存在。

这是当前代码:

if (stripos($_SERVER['REQUEST_URI'],'-parrots') !== false) 
        {echo '<div class="clear"></div><a href="http://www.example.com/parrots/" class="btn"> >> Parrots</a>';}

上面的效果很好。

我试过的两个词:

if (stripos($_SERVER['REQUEST_URI'],'-green','-parrots') !== false) 
        {echo '<div class="clear"></div><a href="http://www.example.com/green-parrots/" class="btn"> >> Green Parrots</a>';}

但这似乎不起作用。

有什么想法吗?

【问题讨论】:

标签: php url stripos


【解决方案1】:

使用stripos(),您有needlehaystack 和偏移量

你最好去找

if ( (stripos($_SERVER['REQUEST_URI'],'-green') !== false) && (stripos($_SERVER['REQUEST_URI'],'-parrot') !== false) )

您可以根据需要使用&amp;&amp;(和)或||(或)

【讨论】:

    【解决方案2】:

    只需使用两个stripos 调用:

    <?php
    if (stripos($_SERVER['REQUEST_URI'],'-parrots') !== false &&
        stripos($_SERVER['REQUEST_URI'],'-green') !== false) {
        // ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多