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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -