How to check how many times something occurs in a string in PHP

前端 未结 5 1037
眼角桃花
眼角桃花 2020-12-19 18:56

I want to check how many instances of the letter a appears in a certain string.

What is the function for this? I need it to return an integer value.

5条回答
  •  别那么骄傲
    2020-12-19 19:57

    You can use the function : substr_count

    Example:

    $str = "I love stackoverflow";
    echo substr_count($str,'o'); // prints 3
    

提交回复
热议问题