root/trunk/includes/smarty_plugins/modifier.utf8.php
| Revision 1, 1.7 KB (checked in by anonymous, 7 years ago) |
|---|
| Line | |
|---|---|
| 1 | <?php |
| 2 | /****************************************************** Open .node *** |
| 3 | * Description: |
| 4 | * Status: Stable. |
| 5 | * Author: Alexandre Dath <alexandre@dotnode.com> |
| 6 | * $Id$ |
| 7 | * |
| 8 | * Copyright (C) 2005 Alexandre Dath <alexandre@dotnode.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software Foundation, |
| 22 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 23 | ******************** http://opensource.ikse.net/projects/dotnode ***/ |
| 24 | |
| 25 | |
| 26 | function smarty_modifier_utf8($Str) { |
| 27 | for ($i=0; $i<strlen($Str); $i++) { |
| 28 | if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb |
| 29 | elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb |
| 30 | elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb |
| 31 | elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb |
| 32 | elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb |
| 33 | elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b |
| 34 | else return utf8_encode($Str); # Does not match any model |
| 35 | for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? |
| 36 | if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80)) |
| 37 | return utf8_encode($Str); |
| 38 | } |
| 39 | } |
| 40 | return $Str; |
| 41 | } |
| 42 | |
| 43 | ?> |
Note: See TracBrowser
for help on using the browser.
