Home  >  Article  >  Backend Development  >  php?如何判断字符串里是否包含某个单词

php?如何判断字符串里是否包含某个单词

WBOY
WBOYOriginal
2016-06-23 13:27:531386browse

<?php     $str="class name for the relations automatically gene_rated below ";     //如何判断$str是否包含  rated ??>


回复讨论(解决方案)

用strpos查找子串是否存在就可以了

stripos() 函数查找字符串在另一字符串中第一次出现的位置(不区分大小写)。

<?phpecho stripos("You love php, I love php too!","PHP");?>

strstr(),stristr(),stripos()都行

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn