fork(1) download
  1. <?php
  2. $str = "àbcÂef"; // visualmente são 6 caracteres, mas internamente são 8 (2 UTF)
  3. $i = 0; // pointer para a string
  4. $c = 0; // contador de caracteres
  5. while ($str[$i]<>"") {
  6. if (ord($str[$i]) >= 127) // se for utf, despreza o caractere seguinte
  7. $i++;
  8. $c++;
  9. $i++;
  10. }
  11. echo $c;
  12.  
Success #stdin #stdout #stderr 0.01s 23508KB
stdin
Standard input is empty
stdout
6
stderr
PHP Notice:  Uninitialized string offset: 8 in /home/9GaY9Y/prog.php on line 5