Returning the number of spaces in a String

0

Not just spaces, but any other letter, for example.

Is there a function that returns this to me?

I've tried:

public function verifica_nome()
{
    return substr_count($this->name, " ");
}

But the same always returns me 0 ...

    
asked by anonymous 10.12.2015 / 01:59

1 answer

2

Use this php function that returns an integer with the quantity: link

echo substr_count("oi tudo bem?"," ");

It will show:

2
    
10.12.2015 / 02:02