English 中文(简体)
如何清理包含有效的 UTF8 字符的 XML 属性的窗体字段?
原标题:How to clean a form field for an XML Attribute that will contain valid UTF8 characters?

我为此挣扎了一段时间。 我有一个多语言的网络应用程序, 可以在某个时候输出 XML 。 这个 XML 可以包含任何语言, 因此我的消毒方法就是禁止某些将 XML 打破的字符被插入。 这个程序并尽可能在 CDATA 中包扎, 但我在属性中有一大堆内容。 我不想拒绝特殊字符, 因为像括号、 句、 句号、 划线、 划线、 划线和 代号这样的完全有效的字符总是被使用, 并且它们一直在工作 。

将所有会打破 XML 属性, 但保留语言完整的最佳方式是什么?

UPDATE:
I found: http://en.wikipedia.org/wiki/CDATA#CDATA-type_attribute_value , which indicated to me that I can describe an attribute as a CDATA section using DTD; however, this is not true it seems.

<?xml version="1.0" ?> 
<!DOCTYPE foo [
  <!ELEMENT foo EMPTY>
  <!ATTLIST foo a CDATA #REQUIRED>
]>
<foo a="&bull;"><![CDATA[ &bull; ]]> </foo>

任何验证者都会抱怨公牛不是属性中的一个实体。 如果您删除属性, 它将会有效 。 另外, 我听到预案是前进的道路, 所以, 如果像上面那样的事情是可能的, 但是使用 XML 示玛, 那将会是真棒 。

谢谢!

最佳回答

此有效

<?xml version="1.0" ?> 
<!DOCTYPE foo [
  <!ELEMENT foo EMPTY>
  <!ATTLIST foo a CDATA #REQUIRED>
]>
<foo a="&amp;bull;"><![CDATA[ &bull; ]]> </foo>

您可以将特殊字符翻译到 html 实体

htmlentities($str);

倒转

html_entity_decode($str);

见:http://www.php.net/manual/en/conference.htmlentities.php

ưμ㼯A

问题回答

您需要做的只是以 标签包住它们。 您也可以投放一个标识 。

attr="<!CDATA[  . htmlentities($value) .  ]]>"




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签