Does preg_replace() change my character set?

后端 未结 1 422
别跟我提以往
别跟我提以往 2021-01-02 17:26

I have the following piece of code which seems to be changing my character set.

     $html = \"à\";
     echo $html;  // result: à
     $html = preg_replace(         


        
相关标签:
1条回答
  • 2021-01-02 17:42

    I have the same problem. It is because of UTF8.

    à is 0xc3a0 in UTF8. In PHP you can write like this: "\xc3\xa0".

    With PCRE the /s match 0xa0 like it was ASCII "Non-breaking space".

    You can use the u flag to resolve the problem.

    $html = preg_replace("/\s/u", "", $html);
    
    0 讨论(0)
提交回复
热议问题