Reputation: 22030
I want to count the number of times "/" appears in this url
Here is my code
$url = "http://www.google.com/images/srpr/nav_logo14.png";
$url_arr = eregi(".",$url);
echo count($url_arr);
It displays on "1"
Upvotes: 0
Views: 413
Reputation: 14365
echo substr_count($url, '/');
See the documentation for more information.
Upvotes: 10
Reputation: 11240
You could use explode()
and count()
:
$url = "http://www.google.com/images/srpr/nav_logo14.png";
$url_arr = explode(".", $url);
echo count($url_arr);
The reason eregi()
returns 1 is that eregi()
returns the length of the matched string.
Upvotes: -1