WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

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

Topic: PHP / MySQLPrev|Next

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.

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

Related FAQ

Here are some more FAQ related to this topic:

Your Feedback:

We would love to hear from you, please drop us a line.