php中substr_count函数用法简介
八月 16, 2010
在PHP可以很容易的利用substr_count函数计算一个指定的子字符串在所给的字符串中出现的次数。
语法:
int substr_count(string $haystack,string $needle[,int $offset[,int $length]])
参数说明:
Haystack:指定要检查的字符串
Needle:指定要插入的字符串
Offset:指定在字符串中何处开始搜索默认为0
Length:指定搜索的长度
实例:
<?php
$haystack=”this is a test contents”;
$handle=”is”;
$count= substr_count($haystack,$handle);
echo “在 “.$haystack.” 字符串中共出现 “.$count.” 次 “.$handle;
?>
Leave a Reply