note 95110 added to function.stripos

From: Date: Mon, 14 Dec 2009 10:09:14 +0000
Subject: note 95110 added to function.stripos
Groups: php.notes 
Request: Send a blank email to php-notes+get-163918@lists.php.net to get a copy of this message
I just want to correct my previous statement about the multi-byte character encoding support. It won't work if the searched string isn't at the position 0. <?php $unicode_string = '¡¤Æ‰æ« “‹‘’›”ϡϿӉԅש؁ضܓܛߨ◎✂➷Ⱡ—test» —–¾½¬ß¹²³´'; $search_for = 'ϡϿӉԅש؁ضܓܛߨ◎✂➷Ⱡ—test'; $position = stripos($unicode_string, $search_for); $position_mb = mb_stripos($unicode_string, $search_for, 0, "UTF-8"); if ($position !== false) { echo "Found using stripos on position $position! \n"; } if ($position_mb !== false) { echo "Found using mb_stripos on position $position_mb!"; } /* Output: Found using stripos on position 32! Found using mb_stripos on position 13! */ ?> See the difference? :p Use mb_stripos() to have an accurate position with Unicode UTF-8 strings. ---- Server IP: 69.147.83.197 Probable Submitter: 68.37.205.26 ---- Manual Page -- http://www.php.net/manual/en/function.stripos.php Edit -- https://master.php.net/note/edit/95110 Del: integrated -- https://master.php.net/note/delete/95110/integrated Del: useless -- https://master.php.net/note/delete/95110/useless Del: bad code -- https://master.php.net/note/delete/95110/bad+code Del: spam -- https://master.php.net/note/delete/95110/spam Del: non-english -- https://master.php.net/note/delete/95110/non-english Del: in docs -- https://master.php.net/note/delete/95110/in+docs Del: other reasons-- https://master.php.net/note/delete/95110 Reject -- https://master.php.net/note/reject/95110 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#163918) next »