mb_strpos index woes
| From: | joseph | Date: | Sun, 12 Mar 2006 12:42:20 +0000 |
| Subject: | mb_strpos index woes | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-231800@lists.php.net to get a copy of this message | ||
hello world.
(my first email)
well, i have this problem with mb_strpos which returns a position for
me. the position is an index into the string, supposedly.
everything works fine excpet for when i index into the array.
i wish to confirm that the position is the character count not the byte
count into the string.
thank you very much.
if i am correct, i would request a change of the word 'character' in
here to mean multi-byte character for clarity sake
mb_strpos() performs multi-byte safe strpos() operation based on number
of characters. needle position is counted from the beginning of the
haystack. First character's position is 0. Second character position is
1, and so on.
code is this:
$french2=<<<SXR
<BR>Il m'arrive d'être égoiste. Je sais.<BR><BR><IMG height=446
src="http://www.u-blog.net/bezabel/img/bdFM-oueb2.jpg"
width=400
border=0><BR>(<A href="http://blogdamned.free.fr/?2005/05">Blog
DAmned</A> pour en savoir plus)
SXR;
$match_pos = mb_strpos($target, $split_pattern,
$present_offset,'UTF-8');
// check for false omitted
while (($match_pos || $first) && $present_offset
< $len ) {
// check for 0 omitted
$diff = $match_pos-$present_offset;
$word = mb_substr($target, $present_offset, $diff);
$mb_len = mb_strlen($word);
if ($mb_len != $diff) if ($debug_my_mb) echo "$mb_len and $diff
are not equal<br>";
$match_pos2 = $mb_len + $present_offset;
if ($match_pos2 != $match_pos) if ($debug_my_mb) echo
"$match_pos and $match_pos2 are not equal<br>";
TEHY ARE EQUAL, HOWEVER
if ($target[$match_pos] != $split_pattern) if ($debug_my_mb)
echo "<br>mismatch of $next_word and $split_pattern<br>";
SAYS IT IS A MISMATCH
therefore must return character count, not byte count.