php - substr_count and strtolower used together give inconsistent results -
i trying use substr_count check occurrence of particular string. code seems giving inconsistent results.
sometimes echoes 1 , 0. wonder if can explain me why happening? thanks!
$val = "hello world ansprüche theme park"; $ne = "ansprüche"; echo substr_count(strtolower($val),$ne);
in string latin charter "ansprüche". first have convert string iso-8859-1 characters encoded utf-8 single-byte iso-8859-1.
use below code. it's working fine.
<?php $val = "hello world ansprüche theme park hello"; $ne = "ansprüche"; echo substr_count(strtolower(utf8_decode($val)), utf8_decode($ne)); ?>
Comments
Post a Comment