1

I have a code that printing properly ascii character upto 127. But its not printing extended ascii characters properly.

$data = "Two Ts and one F.";
foreach (count_chars($data, 0) as $i => $val) {
   echo "There were $val instance(s) of " , chr($i) , " in the string.<br/>";
}

its output same from 128 to 255 is :

There were 0 instance(s) of � in the string.  

I have saved my file in utf-8 encoding

Dhairya Lakhera
  • 4,445
  • 3
  • 35
  • 62

1 Answers1

1

I think i got your point, you need to do like this:-

<?php

$data = "Two Ts and one F.";
foreach (count_chars($data, 0) as $i => $val) {
   echo "There were $val instance(s) of ". utf8_encode(chr($i)) ." in the string.".PHP_EOL;
}

Output:- https://eval.in/925240

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98