Php 停止将大于号转换为HTML实体
我正在用PHP编写一些未验证的XML,因为CDATA元素上的结束大于符号正在转换为HTML实体。代码如下:Php 停止将大于号转换为HTML实体,php,xml,wordpress,plugins,Php,Xml,Wordpress,Plugins,我正在用PHP编写一些未验证的XML,因为CDATA元素上的结束大于符号正在转换为HTML实体。代码如下: $xml .= '<item number="'.$i.'"> <sku>'.$this->get_product_sku($key, $value).'</sku> <description> <![CDATA[
$xml .= '<item number="'.$i.'">
<sku>'.$this->get_product_sku($key, $value).'</sku>
<description>
<![CDATA[
'.get_the_title($value['prodid']).'
]]>
</description>
<qty>'.$value['quantity'].'</qty>
<price>'.$value['price'].'</price>
<extended>'.$value['quantity']*$value['price'].'</extended>
</item>';
关闭的
将变为
,并且XML不会验证。有人能帮我解决这个问题吗
谢谢
编辑:下面是生成XML的整个函数。我只调用并打印此函数。没有对字符串执行任何使其无效的操作
function build_xml($p, $c)
{
global $wpdb;
// Make the billing and shipping data available
$this->determine_shipping_details($p, $c);
$this->determine_billing_details($p, $c);
// Build the XML
$xml = '<?xml version="1.0" ?>
<orderdata batch="'.$p['id'].'">
<order id="'.$p['id'].'">
<orderdate>'.date('m/d/Y h:i:s', $p['date']).'</orderdate>
<store>'.$this->store_id.'</store>
<adcode>OL</adcode>
<username>'.$this->username.'</username>
<password>'.$this->password.'</password>
<billingaddress>
<firstname>'.$this->billing_details['first_name'].'</firstname>
<lastname>'.$this->billing_details['last_name'].'</lastname>
<address1>'.$this->billing_details['address'].'</address1>
<city>'.$this->billing_details['city'].'</city>
<state>'.$this->billing_details['state'].'</state>
<zipcode>'.$this->billing_details['zip'].'</zipcode>
<country>'.$this->billing_details['country'].'</country>
<phone>'.$this->billing_details['phone'].'</phone>
<email>'.$this->billing_details['email'].'</email>
</billingaddress>
<shippingaddress>
<firstname>'.$this->shipping_details['first_name'].'</firstname>
<lastname>'.$this->shipping_details['last_name'].'</lastname>
<address1>'.$this->shipping_details['address'].'</address1>
<city>'.$this->shipping_details['city'].'</city>
<state>'.$this->shipping_details['state'].'</state>
<zipcode>'.$this->shipping_details['zip'].'</zipcode>
<country>'.$this->shipping_details['country'].'</country>
<phone>'.$this->shipping_details['phone'].'</phone>
<email>'.$this->shipping_details['email'].'</email>
</shippingaddress>
<orderdetails>';
// Add the individual items' information to the XML
$i = 1;
foreach($c as $key => $value)
{
$xml .= '<item number="'.$i.'">
<sku>'.$this->get_product_sku($key, $value).'</sku>
<description>
<![CDATA[
'.get_the_title($value['prodid']).'
]]>
</description>
<qty>'.$value['quantity'].'</qty>
<price>'.$value['price'].'</price>
<extended>'.str_replace(stripslashes( get_option('wpsc_thousands_separator') ), '', trim(wpsc_currency_display($value['quantity']*$value['price'], array('display_currency_symbol' => false, 'display_decimal_point' => true, 'display_currency_code' => false, 'display_as_html' => false)))).'</extended>
</item>';
$i++;
}
// Add the order totals
$xml .= '<subtotal>'.str_replace(stripslashes( get_option('wpsc_thousands_separator') ), '', trim(wpsc_currency_display($p['totalprice']-$p['wpec_taxes_total']-$p['base_shipping'], array('display_currency_symbol' => false, 'display_decimal_point' => true, 'display_currency_code' => false, 'display_as_html' => false)))).'</subtotal>
<shipping code="'.'FEG'.'" rate="'.$p['base_shipping'].'" thirdparty="">'.'FEDEX GROUND SERVICE'.'</shipping>
<tax rate="'.$p['wpec_taxes_rate'].'">'.$p['wpec_taxes_total'].'</tax>
<total>'.$p['totalprice'].'</total>
<amountpaid>'.$p['totalprice'].'</amountpaid>
</orderdetails>';
// Close out the tags
$xml .= '</order>
</orderdata>';
return $xml;
}
函数构建xml($p,$c)
{
全球$wpdb;
//使帐单和装运数据可用
$this->确定装运详情($p,$c);
$this->确定账单详情($p,$c);
//构建XML
$xml='0
“.日期('m/d/Y h:i:s',$p['date'])”
“.$this->store_id”
OL
“.$this->username。”
“.$this->密码。”
'.$this->账单详细信息['first\u name']
“.$this->账单详细信息['last\u name']”
“.$this->账单详细信息['address']”
“.$this->billing_details['city']”
“.$this->账单详细信息['state']”
“.$this->billing_details['zip']”
“.$this->账单详细信息['country']”
“.$this->账单详细信息['phone']”
“.$this->账单详细信息['email']”
“.$this->shipping\u details[“first\u name]”
“.$this->shipping\u details['last\u name']”
“.$this->shipping_details['address']”
“.$this->shipping_details['city']”
“.$this->shipping_details['state']”
“.$this->shipping_details['zip']”
“.$this->shipping_details['country']”
“.$this->shipping_details['phone']”
“.$this->shipping_details['email']”
';
//将各个项目的信息添加到XML中
$i=1;
foreach($c作为$key=>$value)
{
$xml.='
“.$this->get_product_sku($key,$value)。”
“.$value['quantity']”
“.$value['price']”
“.str_replace(条斜杠(获取选项('wpsc_千位分隔符')),”,修剪(wpsc_货币显示($value['quantity']*$value['price']),数组('display_currency_symbol'=>false,'display_decimal_point'=>true,'display_currency_代码'=>false,'display_as_html'=>false)))。”
';
$i++;
}
//添加订单总数
$xml.=''.str_替换(带斜杠(获取选项('wpsc_千位分隔符')),'',修剪(wpsc_货币显示($p['totalprice']-$p['wpec_taxes_total']-$p['base_shipping'],数组('display_currency_symbol'=>false,'display_decimal_point'=>true,'display_currency_code'=>false,'display_as_html'=>false))。)
“联邦快递地面服务”
“.$p[“wpec税总额”]”
“.$p[‘总价’]”
“.$p[‘总价’]”
';
//把标签收起来
$xml.='
';
返回$xml;
}
尝试使用
html\u entity\u decode()
或htmlspecialchars\u decode()
。这两种方法都适用于本案例
有目的地对其进行编码:
$xml .= '<item number="'.$i.'">
<sku>'.$this->get_product_sku($key, $value).'</sku>
<description>
<![CDATA[
'.get_the_title($value['prodid']).'
]]>
</description>
<qty>'.$value['quantity'].'</qty>
<price>'.$value['price'].'</price>
<extended>'.$value['quantity']*$value['price'].'</extended>
</item>';
尝试使用
html\u entity\u decode()
或htmlspecialchars\u decode()
。这两种方法都适用于本案例
有目的地对其进行编码:
$xml .= '<item number="'.$i.'">
<sku>'.$this->get_product_sku($key, $value).'</sku>
<description>
<![CDATA[
'.get_the_title($value['prodid']).'
]]>
</description>
<qty>'.$value['quantity'].'</qty>
<price>'.$value['price'].'</price>
<extended>'.$value['quantity']*$value['price'].'</extended>
</item>';
当我在我的Web服务器上运行它时,它的格式是正确的。你在设置标题吗? 尝试
标题('Content-type:text/xml')
echo$xml代码>当我在我的Web服务器上运行它时,它的格式是正确的。你在设置标题吗?
尝试
标题('Content-type:text/xml')
echo$xml代码>根据您随问题提供的信息,很难明确说出输出被破坏的原因
因此,您需要逐步完成您的程序,查看XML构建的每个点(已经是您问题的一部分)以及wordpress设置对其各种插件和主题的进一步处理
为此,有必要了解这些修改会出现在何处。
此外,您还需要一个方法来按原样查看输出,这意味着保持不变。如果在浏览器中查看源代码,通常情况并非如此:浏览器在显示输出之前会更改输出,因此通常最好使用HTTP客户端(如curl
)在命令行中转储请求响应,您可以使用该客户端选择性地将输出转储到文件中,并在编辑器不变的情况下查看
让我们回顾一下:
XML的创建必须是正确的第一手资料
XML可能会被wordpress更改
浏览器可能会更改XML
这可能需要检查很多点:
1.XML的创建必须是正确的第一手资料。
首先,我将单独研究get\u title($value['prodid'])
的返回值,这样您就知道您要处理什么了。可能它已经包含了
?这将解释单个
可能来自哪里。但是,在
中使用它是有效的。这只是为了闻一闻,了解以后可能发生的事情
在讨论的单个值旁边,您应该确保在进一步处理XML之前,XML本身看起来是正确的,这意味着在函数末尾。您可以通过在从方法返回之前将其输出并结束/退出应用程序来防止进一步处理:
echo "Test output:\n\n", $xml; die();
然后查看输出。看起来对吗?有问题的
是否已经在cdata部分的末尾?如果是,您知道问题已经存在于函数内部。如果不是,你知道问题是
echo "Test output:\n\n", $xml; die();
function the_content($more_link_text = null, $stripteaser = false) {
$content = get_the_content($more_link_text, $stripteaser);
$content = apply_filters('the_content', $content);
/** $content = str_replace(']]>', ']]>', $content); */