0

Counts how many times a substring occurs in a string in PHP

 8 months ago
source link: https://www.laravelcode.com/post/counts-how-many-times-a-substring-occurs-in-a-string-in-php
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Counts how many times a substring occurs in a string in PHP

  1232 views

  2 years ago

PHP

Use the PHP substr_count() function

You can use the PHP substr_count() function to find out how many times a given substring is appears or repeated inside a string. Let's try out an example to see how it works:

<?php
$quote = "Try not to become a man of success, but rather try to become a man of value.";
 
echo substr_count($quote, 'man'); // Outputs: 2
?>
Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK