special characters - Compare strings with middle dot not working in PHP -


i string database, encoded utf8_unicode_ci. might contain middle dot character (⋅) , have find out using strcmp. if show string in html directly, character displayed without problem when comparison, results not expect.

for example:

$string = "⋅⋅⋅ string starts middle dots"; $result = strcmp(substr($string , 0, 2), "⋅⋅"); 

the results not 0, think should be. php file saved utf-8 encoding. missing here? happens if take string variable instead of database

php's substr not take unicode characters single character.

the dot you're using 3 characters, 0xe2 0x8b 0x85.

so either use mb_substr, or use different offset:

<?php  $string = "⋅⋅⋅ string starts middle dots"; $result = strcmp(mb_substr($string , 0, 2), "⋅⋅");  var_dump($result); 

or if mb_* functions don't exist:

<?php  $string = "⋅⋅⋅ string starts middle dots"; $result = strcmp(substr($string , 0, 6), "⋅⋅");  var_dump($result); 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -