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

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

WBOY
Release: 2016-06-23 13:27:53
Original
1401 people have browsed it

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


回复讨论(解决方案)

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

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

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

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template