XML 不间断空白

发布于 2024-12-15 08:12:57 字数 404 浏览 4 评论 0原文

我认为目前我的困境的原因是不间断的空白。

看来一些令人讨厌的角色已经从我们的后台系统进入了我们的 MySQL 数据库。当我尝试使用 PHP 的 XMLWriter 运行 XML 输出时,但有大量这些愚蠢的字符进入该字段。

它们在nano中显示为^K,在gedit中显示为奇怪的方框,当您删除时在 MySQL 中手动删除它们,它们不会占用物理空间,尽管您知道您已经删除了某些内容。

请帮我摆脱他们!

这是目前的噩梦行(我已经跳过了 XMLWriter 构建的其余部分)。

$writer->writeElement("description",$myitem->description);

I think the cause of my woes at present is the non-breaking white space.

It appears some nasty characters have found their way into our MySQL database from our back office systems. So as I'm trying to run an XML output using PHP's XMLWriter, but there's loads of these silly characters getting into the field.

They're displayed in nano as ^K, in gedit as a weird square box, and when you delete them manually in MySQL they don't take up a phsyical space, despite that you know you've deleted something.

Please help me get rid of them!

Here is the line that is the nightmare at present (i've skipped out the rest of the XMLWriter buildup).

$writer->writeElement("description",$myitem->description);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

画骨成沙 2024-12-22 08:12:57

在确定要删除的具体字符(并且它是二进制序列)后,您可以将其删除。例如 str_replace

$binSequence = "..."; // the binary representation of the character in question
$descriptionFiltered = str_replace($binSequence, '', $myitem->description);
$writer->writeElement("description", $descriptionFiltered);

您尚未指定您正在谈论的具体字符,所以我还不能指定二进制序列。此外,如果您谈论的是一组字符,过滤可能会有所不同。

After you have identified which character specifically you want to remove (and it's binary sequence), you can just remove it. For example with str_replace:

$binSequence = "..."; // the binary representation of the character in question
$descriptionFiltered = str_replace($binSequence, '', $myitem->description);
$writer->writeElement("description", $descriptionFiltered);

You have not specified yet about which concrete character you're talking, so I can't yet specify the binary sequence. Also if you're talking about a group of characters, the filtering might vary a bit.

蓝眸 2024-12-22 08:12:57

似乎它们是垂直制表符,ASCII x0B。您应该能够在 MySQL 中替换它们:

SELECT REPLACE('\v', '', `value`) WHERE key = 'foo';

但是,官方参考没有具体提到\v。如果它不起作用,您可以随后在 PHP 中使用简单的 str_replace 删除它(自 PHP 5.2.5 起):

str_replace("\v", '', $result);

Seems that they are vertical tabs, ASCII x0B. You should be able to REPLACE them in MySQL:

SELECT REPLACE('\v', '', `value`) WHERE key = 'foo';

However, the official reference doesn't mention \v specifically. If it doesn't work, you can remove it afterwards in PHP with a simple str_replace (since PHP 5.2.5):

str_replace("\v", '', $result);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文