Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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
?>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now