Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTF8 encode deprecated in PHP 8.x #20

Open
mae1cum77 opened this issue Mar 5, 2024 · 0 comments
Open

UTF8 encode deprecated in PHP 8.x #20

mae1cum77 opened this issue Mar 5, 2024 · 0 comments

Comments

@mae1cum77
Copy link

Script getting utf8_encoding() is deprecated message in PHP 8.x, not working due to it.

function endWithJsonResponse($responseData, $filename = NULL) {

  if($responseData) {
    array_walk_recursive($responseData, function(&$value, &$key) {
      if(is_string($value)) $value = utf8_encode($value);
    });  
  }

Needs to be changed to something like:

function iso8859_1_to_utf8(string $s): string {
  $s .= $s;
  $len = \strlen($s);

  for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) {
      switch (true) {
          case $s[$i] < "\x80": $s[$j] = $s[$i]; break;
          case $s[$i] < "\xC0": $s[$j] = "\xC2"; $s[++$j] = $s[$i]; break;
          default: $s[$j] = "\xC3"; $s[++$j] = \chr(\ord($s[$i]) - 64); break;
      }
  }

  return substr($s, 0, $j);
}

function endWithJsonResponse($responseData, $filename = NULL) {

  if($responseData) {
    array_walk_recursive($responseData, function(&$value, &$key) {
      if(is_string($value)) $value = iso8859_1_to_utf8($value);
    });  
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant