如何从字符串中删除NULL字符 [英] How can I remove the NULL character from string

查看:518
本文介绍了如何从字符串中删除NULL字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP变量,其中包含一个表示XML结构的字符串.该字符串包含回义字符,这些字符不允许我从该字符串构建新的SimpleXMLElement对象.我没有办法询问内容的来源以修改其响应,因此在创建SimpleXMLElement对象之前,需要对此字符串执行一些清除操作.

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 from the string. I dont have a way to ask the source of the content to modify their response, so I need to execute some cleaning on this string before I create a SimpleXMLElement object.

我相信引起问题的字符是� (0x00(00)HEX)字符,它位于此字符串XML的文本节点之一之内.

I believe the character causing the problem is a � (0x00 (00) HEX) character, and its located within one of the Text Nodes of this string XML.

删除此字符或其他可能破坏SimpleXMLElement对象的字符的最佳方法是什么.

What is the best way to remove this character or other characters that could break the SimpleXMLElement object.

推荐答案

$text = str_replace("\0", "", $text);

将替换$text字符串中的所有空字符.如果要进行多次替换,还可以为前两个参数提供数组.

will replace all null characters in the $text string. You can also supply arrays for the first two arguments, if you want to do multiple replacements.

这篇关于如何从字符串中删除NULL字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆