3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function utf8($num) { if($num<=0x7F) return chr($num); if($num<=0x7FF) return chr(($num>>6)+192).chr(($num&63)+128); if($num<=0xFFFF) return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128); if($num<=0x1FFFFF) return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128).chr(($num&63)+128); return ''; } function uniord($c) { $ord0 = ord($c{0}); if ($ord0>=0 && $ord0<=127) return $ord0; $ord1 = ord($c{1}); if ($ord0>=192 && $ord0<=223) return ($ord0-192)*64 + ($ord1-128); $ord2 = ord($c{2}); if ($ord0>=224 && $ord0<=239) return ($ord0-224)*4096 + ($ord1-128)*64 + ($ord2-128); $ord3 = ord($c{3}); if ($ord0>=240 && $ord0<=247) return ($ord0-240)*262144 + ($ord1-128)*4096 + ($ord2-128)*64 + ($ord3-128); return false; } //echo uniord('á'); 225 //echo utf8(0xE1); á //echo utf8(0x67); $strTest='Sali ¿te casarias conmigo?'; for($i = 0, $n = mb_strlen($strTest); $i < $n; $i++) { $mbchar = mb_substr($strTest, $i, 1); echo 'current char: '.$mbchar.' '; echo 'uniord= '.uniord($mbchar).' '; echo 'prev dec= '.(uniord($mbchar)+1).' '; echo 'prev hex= '.dechex(uniord($mbchar)+1).' '; echo 'prev char= '.utf8((uniord($mbchar)+1)).' - '; }
Output for 5.6.8 - 7.1.0
current char: S uniord= 83 prev dec= 84 prev hex= 54 prev char= T - current char: a uniord= 97 prev dec= 98 prev hex= 62 prev char= b - current char: l uniord= 108 prev dec= 109 prev hex= 6d prev char= m - current char: i uniord= 105 prev dec= 106 prev hex= 6a prev char= j - current char: uniord= 32 prev dec= 33 prev hex= 21 prev char= ! - current char: ¿ uniord= 191 prev dec= 192 prev hex= c0 prev char= À - current char: t uniord= 116 prev dec= 117 prev hex= 75 prev char= u - current char: e uniord= 101 prev dec= 102 prev hex= 66 prev char= f - current char: uniord= 32 prev dec= 33 prev hex= 21 prev char= ! - current char: c uniord= 99 prev dec= 100 prev hex= 64 prev char= d - current char: a uniord= 97 prev dec= 98 prev hex= 62 prev char= b - current char: s uniord= 115 prev dec= 116 prev hex= 74 prev char= t - current char: a uniord= 97 prev dec= 98 prev hex= 62 prev char= b - current char: r uniord= 114 prev dec= 115 prev hex= 73 prev char= s - current char: i uniord= 105 prev dec= 106 prev hex= 6a prev char= j - current char: a uniord= 97 prev dec= 98 prev hex= 62 prev char= b - current char: s uniord= 115 prev dec= 116 prev hex= 74 prev char= t - current char: uniord= 32 prev dec= 33 prev hex= 21 prev char= ! - current char: c uniord= 99 prev dec= 100 prev hex= 64 prev char= d - current char: o uniord= 111 prev dec= 112 prev hex= 70 prev char= p - current char: n uniord= 110 prev dec= 111 prev hex= 6f prev char= o - current char: m uniord= 109 prev dec= 110 prev hex= 6e prev char= n - current char: i uniord= 105 prev dec= 106 prev hex= 6a prev char= j - current char: g uniord= 103 prev dec= 104 prev hex= 68 prev char= h - current char: o uniord= 111 prev dec= 112 prev hex= 70 prev char= p - current char: ? uniord= 63 prev dec= 64 prev hex= 40 prev char= @ -
Output for 5.2.10 - 5.5.35
current char: S uniord= 83 prev dec= 84 prev hex= 54 prev char= T - current char: a uniord= 97 prev dec= 98 prev hex= 62 prev char= b - current char: l uniord= 108 prev dec= 109 prev hex= 6d prev char= m - current char: i uniord= 105 prev dec= 106 prev hex= 6a prev char= j - current char: uniord= 32 prev dec= 33 prev hex= 21 prev char= ! - current char: � Notice: Uninitialized string offset: 1 in /in/mbZi2 on line 14 uniord= 0 Notice: Uninitialized string offset: 1 in /in/mbZi2 on line 14 prev dec= 1 Notice: Uninitialized string offset: 1 in /in/mbZi2 on line 14 prev hex= 1 Notice: Uninitialized string offset: 1 in /in/mbZi2 on line 14 prev char=  - current char: � Notice: Uninitialized string offset: 1 in /in/mbZi2 on line 14 Notice: Uninitialized string offset: 2 in /in/mbZi2 on line 15 Notice: Uninitialized string offset: 3 in /in/mbZi2 on line 16 uniord= Notice: Uninitialized string offset: 1 in /in/mbZi2 on line 14 Notice: Uninitialized string offset: 2 in /in/mbZi2 on line 15 Notice: Uninitialized string offset: 3 in /in/mbZi2 on line 16 prev dec= 1 Notice: Uninitialized string offset: 1 in /in/mbZi2 on line 14 Notice: Uninitialized string offset: 2 in /in/mbZi2 on line 15 Notice: Uninitialized string offset: 3 in /in/mbZi2 on line 16 prev hex= 1 Notice: Uninitialized string offset: 1 in /in/mbZi2 on line 14 Notice: Uninitialized string offset: 2 in /in/mbZi2 on line 15 Notice: Uninitialized string offset: 3 in /in/mbZi2 on line 16 prev char=  - current char: t uniord= 116 prev dec= 117 prev hex= 75 prev char= u - current char: e uniord= 101 prev dec= 102 prev hex= 66 prev char= f - current char: uniord= 32 prev dec= 33 prev hex= 21 prev char= ! - current char: c uniord= 99 prev dec= 100 prev hex= 64 prev char= d - current char: a uniord= 97 prev dec= 98 prev hex= 62 prev char= b - current char: s uniord= 115 prev dec= 116 prev hex= 74 prev char= t - current char: a uniord= 97 prev dec= 98 prev hex= 62 prev char= b - current char: r uniord= 114 prev dec= 115 prev hex= 73 prev char= s - current char: i uniord= 105 prev dec= 106 prev hex= 6a prev char= j - current char: a uniord= 97 prev dec= 98 prev hex= 62 prev char= b - current char: s uniord= 115 prev dec= 116 prev hex= 74 prev char= t - current char: uniord= 32 prev dec= 33 prev hex= 21 prev char= ! - current char: c uniord= 99 prev dec= 100 prev hex= 64 prev char= d - current char: o uniord= 111 prev dec= 112 prev hex= 70 prev char= p - current char: n uniord= 110 prev dec= 111 prev hex= 6f prev char= o - current char: m uniord= 109 prev dec= 110 prev hex= 6e prev char= n - current char: i uniord= 105 prev dec= 106 prev hex= 6a prev char= j - current char: g uniord= 103 prev dec= 104 prev hex= 68 prev char= h - current char: o uniord= 111 prev dec= 112 prev hex= 70 prev char= p - current char: ? uniord= 63 prev dec= 64 prev hex= 40 prev char= @ -
Output for 4.3.0 - 5.2.9
current char: S uniord= 83 prev dec= 84 prev hex= 54 prev char= T - current char: a uniord= 97 prev dec= 98 prev hex= 62 prev char= b - current char: l uniord= 108 prev dec= 109 prev hex= 6d prev char= m - current char: i uniord= 105 prev dec= 106 prev hex= 6a prev char= j - current char: uniord= 32 prev dec= 33 prev hex= 21 prev char= ! - current char: � Notice: Uninitialized string offset: 1 in /in/mbZi2 on line 14 uniord= 0 Notice: Uninitialized string offset: 1 in /in/mbZi2 on line 14 prev dec= 1 Notice: Uninitialized string offset: 1 in /in/mbZi2 on line 14 prev hex= 1 Notice: Uninitialized string offset: 1 in /in/mbZi2 on line 14 prev char=  - current char: � Notice: Uninitialized string offset: 1 in /in/mbZi2 on line 14 Notice: Uninitialized string offset: 2 in /in/mbZi2 on line 15 Notice: Uninitialized string offset: 3 in /in/mbZi2 on line 16 uniord= Notice: Uninitialized string offset: 1 in /in/mbZi2 on line 14 Notice: Uninitialized string offset: 2 in /in/mbZi2 on line 15 Notice: Uninitialized string offset: 3 in /in/mbZi2 on line 16 prev dec= 1 Notice: Uninitialized string offset: 1 in /in/mbZi2 on line 14 Notice: Uninitialized string offset: 2 in /in/mbZi2 on line 15 Notice: Uninitialized string offset: 3 in /in/mbZi2 on line 16 prev hex= 1 Notice: Uninitialized string offset: 1 in /in/mbZi2 on line 14 Notice: Uninitialized string offset: 2 in /in/mbZi2 on line 15 Notice: Uninitialized string offset: 3 in /in/mbZi2 on line 16 prev char=  - current char: t uniord= 116 prev dec= 117 prev hex= 75 prev char= u - current char: e uniord= 101 prev dec= 102 prev hex= 66 prev char= f - current char: uniord= 32 prev dec= 33 prev hex= 21 prev char= ! - current char: c uniord= 99 prev dec= 100 prev hex= 64 prev char= d - current char: a uniord= 97 prev dec= 98 prev hex= 62 prev char= b - current char: s uniord= 115 prev dec= 116 prev hex= 74 prev char= t - current char: a uniord= 97 prev dec= 98 prev hex= 62 prev char= b - current char: r uniord= 114 prev dec= 115 prev hex= 73 prev char= s - current char: i uniord= 105 prev dec= 106 prev hex= 6a prev char= j - current char: a uniord= 97 prev dec= 98 prev hex= 62 prev char= b - current char: s uniord= 115 prev dec= 116 prev hex= 74 prev char= t - current char: uniord= 32 prev dec= 33 prev hex= 21 prev char= ! - current char: c uniord= 99 prev dec= 100 prev hex= 64 prev char= d - current char: o uniord= 111 prev dec= 112 prev hex= 70 prev char= p - current char: n uniord= 110 prev dec= 111 prev hex= 6f prev char= o - current char: m uniord= 109 prev dec= 110 prev hex= 6e prev char= n - current char: i uniord= 105 prev dec= 106 prev hex= 6a prev char= j - current char: g uniord= 103 prev dec= 104 prev hex= 68 prev char= h - current char: o uniord= 111 prev dec= 112 prev hex= 70 prev char= p - current char: ? uniord= 63 prev dec= 64 prev hex= 40 prev char= @ -