How to find word in string of words and numbers

This question already has an answer here:

  • How do I check if a string contains a specific word? 37 answers

  • This is how you do it with regex:

    $needle = "/this/";
    echo preg_match($needle, $haystack);
    


    This will return 1 one if it matches else 0


    You don't need regex to do this. As already mentioned in comments use strpos():

    if(strpos($heystack, $needle) !== false) {
    // contains
    }
    

    尝试这个:

    $haystack = "451516178jjgsjkjjssbbziznbdkbnjv.bvkljk_isikjsksjkthisjkhkjhkjh4364765467";
    $needle = "this";
    
    $string = strpos($haystack, $needle);
    
    if($string === false)
     echo "false";
    else
     echo "true";
    
    链接地址: http://www.djcxy.com/p/13132.html

    上一篇: 通过php查找字符串中的第一个数字位置

    下一篇: 如何在字词和数字串中找到单词