PHP检查字符串中是否包含部分或整个单词

时间:2012-03-05 22:35:51

标签: php

我有这两个字符串:

blablab/wp-forum.php?link

blablab/wp-forum.php

如果第二个一个第一个,那么如何检查PHP?

我找不到一种简单易行的方法。

由于

3 个答案:

答案 0 :(得分:2)

查看函数strstr的文档 或strpos
preg_match

答案 1 :(得分:1)

$str = "blablab/wp-forum.php?link";
$find = "blablab/wp-forum.php";

$position = strpos($str, $find);

if($position !== FALSE)   // !== operator to check the type as well. As, strpos returns 0, if found in first position
{
   echo "String contains searched string";
}

答案 2 :(得分:0)

您可以使用strpos找到第一次出现此类字符串

      <?php 
      $pos = strpos($largerString,$fimdMe);
      if($pos === false) {
        // string $findMe not found in $largerString
      }
     else {
      // found it 
    }
    ?>