How can I remove the NULL character from string

前端 未结 3 1101
孤街浪徒
孤街浪徒 2020-12-28 17:23

I have a PHP variable that contains a string which represents an XML structure. This string contains ilegal characters that dont let me build a new SimpleXMLElement object f

3条回答
  •  轮回少年
    2020-12-28 17:54

    trim() will also remove null characters, from either end of the source string (but not within).

    $text = trim($text);
    

    I've found this useful for socket server communication, especially when passing JSON around, as a null character causes json_decode() to return null.

提交回复
热议问题