Different charset on different server?

后端 未结 2 505
没有蜡笔的小新
没有蜡笔的小新 2020-12-21 15:51

I\'ve just tested locally my web application, everything works fine, but after uploading to server application behaves differently. I use function formatiraj_string_url to c

相关标签:
2条回答
  • 2020-12-21 16:20

    Which charset is your file written in?

    Since you have written the characters you would like to replace directly into your code, as strings, they are encoded in whatever charset the file uses. If that charset differs from what you get from the browser, your functions aren't going to work.

    The important point you need to keep in mind, is to always keep track of the charset your strings are encoded with, and convert when neccessary.

    Take a look at Kore Nordmanns FAQ about charsets in PHP for some more pointers about charsets.

    0 讨论(0)
  • 2020-12-21 16:30

    I recommend you rely on existing, highly-tested code to do this. I believe all these functions assume UTF-8 input and output 7-bit ASCII:

    • remove_accents() from Wordpress
    • Drupal's transliteration module (would require a little work to untie it from Drupal)
    • utf8_to_ascii() from the venerable PHP UTF8 project
    • friendly_url() by Jakub Vrána
    • Doctrine_Inflector::urlize()
    • slugify() looks solid
    0 讨论(0)
提交回复
热议问题