PHP replacing special characters like à->a, è->e

前端 未结 8 1769
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 14:20

I have php document signup.php which save the content from form (in form.php document) to MySQL base. The problem arises when I want to reformat the input content. I want do

8条回答
  •  一向
    一向 (楼主)
    2020-11-27 14:58

    The string $chain is in the same character encoding as the characters in the array - it's possible, even likely, that the $first_name string is in a different encoding, and so those characters don't match. You might want to try using the multibyte string functions instead.

    Try mb_convert_encoding. You might also want to try using HTML_ENTITIES as the to_encoding parameter, then you don't need to worry about how the characters will get converted - it will be very predictable.

    Assuming your input to this script is in UTF-8, probably not a bad place to start...

    $first_name = mb_convert_encoding($first_name, "HTML-ENTITIES", "UTF-8"); 
    

提交回复
热议问题