Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

There are two issues with your otherwise elegant approach:

  1. iconv silently cuts the string if a disallowed UTF-8 character is present. The solution would be to add //IGNORE to the iconv() call but 1/ a bug in glibc seems to prevent this 2/ PHP developers don't seem to want to implement a work-around. An option is to remove invalid characters yourself:

    ini_set('mbstring.substitute_character', "none"); 
    $text= mb_convert_encoding($text, 'UTF-8', 'UTF-8'); 
    
  2. You're not removing all characters that are present in ASCII but disallowed in a URL: see this StackOverflow answer see this StackOverflow answer.

There are two issues with your otherwise elegant approach:

  1. iconv silently cuts the string if a disallowed UTF-8 character is present. The solution would be to add //IGNORE to the iconv() call but 1/ a bug in glibc seems to prevent this 2/ PHP developers don't seem to want to implement a work-around. An option is to remove invalid characters yourself:

    ini_set('mbstring.substitute_character', "none"); 
    $text= mb_convert_encoding($text, 'UTF-8', 'UTF-8'); 
    
  2. You're not removing all characters that are present in ASCII but disallowed in a URL: see this StackOverflow answer.

There are two issues with your otherwise elegant approach:

  1. iconv silently cuts the string if a disallowed UTF-8 character is present. The solution would be to add //IGNORE to the iconv() call but 1/ a bug in glibc seems to prevent this 2/ PHP developers don't seem to want to implement a work-around. An option is to remove invalid characters yourself:

    ini_set('mbstring.substitute_character', "none"); 
    $text= mb_convert_encoding($text, 'UTF-8', 'UTF-8'); 
    
  2. You're not removing all characters that are present in ASCII but disallowed in a URL: see this StackOverflow answer.

Source Link
Quentin Pradet
  • 7.1k
  • 1
  • 25
  • 44

There are two issues with your otherwise elegant approach:

  1. iconv silently cuts the string if a disallowed UTF-8 character is present. The solution would be to add //IGNORE to the iconv() call but 1/ a bug in glibc seems to prevent this 2/ PHP developers don't seem to want to implement a work-around. An option is to remove invalid characters yourself:

    ini_set('mbstring.substitute_character', "none"); 
    $text= mb_convert_encoding($text, 'UTF-8', 'UTF-8'); 
    
  2. You're not removing all characters that are present in ASCII but disallowed in a URL: see this StackOverflow answer.

lang-php

AltStyle によって変換されたページ (->オリジナル) /