Home > Backend Development > PHP Tutorial > !判断字符串是否包含的正则或算法

!判断字符串是否包含的正则或算法

WBOY
Release: 2016-06-13 12:03:55
Original
1277 people have browsed it

求助!判断字符串是否包含的正则或算法!
一个查询字符串比如ab;字符串acbcdc,其中包含了ab可以查询到。最重要的一点,查询的字符串,ab有可能不只两个字符。或是abcd;只要字符串当中任意位置包含此字符串就可以匹配成功!
这个算法怎么写呢?或者是用正则表达式能行吗?

------解决方案--------------------

$s = 'acbcdc';<br />$f = 'ab';<br />$d = array_diff(str_split($f), str_split($s));<br />echo empty($d) ? true : false;
Copy after login

------解决方案--------------------
$a = 'acbcdc';<br />$b = 'ab';<br />var_dump(preg_match("/$b/", $a));
Copy after login

Related labels:
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