超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<substr_comparesubstr_replace>
Last updated: Fri, 22 Jun 2007

substr_count

(PHP 4 , PHP 5)

substr_count -- Count the number of substring occurrences

Description

int substr_count ( string haystack, string needle)

substr_count() returns the number of times the needle substring occurs in the haystack string. Please note that needle is case sensitive.

例子 1. substr_count() example

<?php
echo substr_count("This is a test", "is"); // prints out 2
?>

See also count_chars(), strpos(), substr(), and strstr().




add a note add a note User Contributed Notes
substr_count
Jesse at bend dot com
09-Jan-2001 11:58
I am not certain why the above fellah is worried about case sensitivity, ereg functions are mighty slow.. and if you need a case insensitive count, try this:

substr_count(strtolower($haystack), strtolower($needle))

<substr_comparesubstr_replace>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22