php 查找字符串是否包含指定子串

作者: dreamfly 分类: php 发布时间: 2019-01-19 22:05

php对于字符串操作封装了许多高性能的函数,因为web里面经常要做一些对字符的修改操作,所以这也是为什么php在web开发里面这么流行,开发效率这么高的一个原因。

今天主要讲解php中如何判断一个字符串中是否包含子串。

  1. 可以使用strpos来进行判断。

  2. 可以使用strstr来进行判断

  3. 通过explode进行判断

这里面最常用的就是strpos来判断

$str = "梦回故里是一个非常好的技术博客";

if(strpos("梦回故里")!==false){

    echo "包含";

}else{
    echo "不包含";

}

通过explode进行判断

$str = "梦回故里是一个非常好的技术博客";

$arr = explode("梦回故里",$str);

if(count($arr)>1){

    echo "包含";

}else{

    echo "不包含";

}

梦回故里手札

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

7条评论
  • Acousty

    2022年9月1日 10:06

    tadalafil cialis from india It is the greatest overall otc pills for erectile dysfunction that meets all criteria and comes with a 100-day money-back guarantee

  • Kebyecove

    2022年9月3日 14:28

    Then they don t have any other Cialis generic Ranbaxy asked buy priligy on the internet without a prescription Herbal Viagra

  • dwerbus

    2022年9月5日 12:40

    Best ED Pill Delivery Services cialis coupon

  • pacyImmaw

    2022年9月7日 15:01

    I ve been able to cum and then jump right back up again brand name cialis online 4 mg once daily for the treatment of LUTS BPH in an international, placebo-controlled, randomized, double-blind, 12-week trial comparing separately and independently these two drugs with placebo

  • ensuece

    2022年9月10日 12:35

    Since progesterone is produced by the empty follicle after an egg is released, a lack of ovulation means there is no empty follicle to produce progesterone, and therefore it cannot be metabolized into PdG. how to order clomid on line in canada DHT causes miniaturization of the hair follicles, causing them to thin or even fall out.

  • extedia

    2022年9月13日 14:46

    Most doctors like standard protocols because they are what generally works. nolvadex dose for pct When combined with Arimistane, you can expect increased muscle mass, strength, and vascularity.

  • AnnoutFus

    2022年9月17日 05:41

    doxycycline side effects in dogs If the characteristic features of nerve agent poisoning are present, however, antidotal treatment should not be delayed until the result is available.

发表评论

您的电子邮箱地址不会被公开。