note 32160 modified in function.str-word-count by aidan

From: Date: Sat, 26 Jun 2004 06:17:01 +0000
Subject: note 32160 modified in function.str-word-count by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71719@lists.php.net to get a copy of this message
if string doesn't contain the space " ", the explode method doesn't do anything, so i've wrote this and it seems works better ... i don't know about time and resource <?php function str_incounter($match,$string) { $count_match = 0; for($i=0;$i<strlen($string);$i++) { if(strtolower(substr($string,$i,strlen($match)))==strtolower($match)) { $count_match++; } } return $count_match; } ?> example <?php $string = "something:something!!something"; $count_some = str_incounter("something",$string); // will return 3 ?> --was-- if string doesn't contain the space " ", the explode method doesn't do anything, so i've wrote this and it seems works better ... i don't know about time and resource function str_incounter($match,$string) { $count_match = 0; for($i=0;$i<strlen($string);$i++) { if(strtolower(substr($string,$i,strlen($match)))==strtolower($match)) { $count_match++; } } return $count_match; } // example $string = "something:something!!something"; $count_some = str_incounter("something",$string); // will return 3 http://php.net/manual/en/function.str-word-count.php

« previous php.notes (#71719) next »