Shaggie
Shaggie

Reputation: 1829

How to count occurrences of special type of character in string in php

I have a string

Hobbies#14285723739878005#reading#Reading

I need the count of number of occurrence of '#' in the string. How to get that?

Upvotes: 0

Views: 84

Answers (2)

Dave
Dave

Reputation: 362

substr_count() should do what you need:

http://www.w3schools.com/php/func_string_substr_count.asp

Upvotes: 0

RaMeSh
RaMeSh

Reputation: 3424

try this code:

<?php
echo substr_count("Hobbies#14285723739878005#reading#Reading","#");
?>

Output:-

3

For your reference Click Here

Upvotes: 4

Related Questions