• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ Contributions (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

utf8_char2byte

Post a bug fix, a new feature, a theme ...

Moderators: OldWolf, re*s.t.a.r.s.*2

Post a reply
3 posts • Page 1 of 1

Postby jwaldek » Thu Oct 04, 2007 8:46 am

i've got some php errors on error_reporting E_ALL in function utf8_char2byte_pos($str,$pos)
this is my proposition of this function:

Code: Select all
if (!function_exists('utf8_char2byte_pos')) {
  function utf8_char2byte_pos($str,$pos)    {
    $n = 0;                // number of characters found
    $p = abs($pos);        // number of characters wanted
 
    if ($pos >= 0)    {
      $i = 0;
      $d = 1;
    } else {
      $i = strlen($str)-1;
      $d = -1;
    }
 
    for( ; isset($str{$i})&&strlen($str{$i}) && $n<$p; $i+=$d)    {
      $c = (int)ord($str{$i});
      if (!($c & 0x80))    // single-byte (0xxxxxx)
        $n++;
      elseif (($c & 0xC0) == 0xC0)    // multi-byte starting byte (11xxxxxx)
        $n++;
    }
    if (isset($str{$i})&&!strlen($str{$i}))    return false; // offset beyond string length
 
    if ($pos >= 0)    {
      // skip trailing multi-byte data bytes
         if(isset($str{$i})){
         while ((ord($str{$i}) & 0x80) && !(ord($str{$i}) & 0x40)) { $i++; }
         }
    } else {
      // correct offset
      $i++;
    }
 
    return $i;
  }
}
jwaldek
Member
 
Posts: 19
Joined: Thu Oct 04, 2007 8:37 am
Top

Postby phpfreechat » Thu Oct 04, 2007 8:51 am

Could you explain what did you changed ?
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby jwaldek » Thu Oct 04, 2007 12:47 pm

add isset($str{$i})
because php sometimes throw notices about Undefined variable/ table index "$str{$i}" on error_reporting(E_ALL)
jwaldek
Member
 
Posts: 19
Joined: Thu Oct 04, 2007 8:37 am
Top


Post a reply
3 posts • Page 1 of 1

Return to Contributions (v1.x)

Who is online

Users browsing this forum: No registered users and 9 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub