Note that there are some explanatory texts on larger screens.

plurals
  1. POStop greater than sign converting to HTML entity
    text
    copied!<p>I'm writing some XML in PHP that is not validating because the closing greater than sign on a CDATA element is getting converted to an HTML entity. The code is as follows:</p> <pre><code>$xml .= '&lt;item number="'.$i.'"&gt; &lt;sku&gt;'.$this-&gt;get_product_sku($key, $value).'&lt;/sku&gt; &lt;description&gt; &lt;![CDATA[ '.get_the_title($value['prodid']).' ]]&gt; &lt;/description&gt; &lt;qty&gt;'.$value['quantity'].'&lt;/qty&gt; &lt;price&gt;'.$value['price'].'&lt;/price&gt; &lt;extended&gt;'.$value['quantity']*$value['price'].'&lt;/extended&gt; &lt;/item&gt;'; </code></pre> <p>The resulting XML looks something like the following when printed out using <code>var_dump</code> or <code>print_r</code>:</p> <pre><code>&lt;item number="2"&gt; &lt;sku&gt;45NK2&lt;/sku&gt; &lt;description&gt; &lt;![CDATA[ Test Product ]]&amp;gt; &lt;/description&gt; &lt;qty&gt;2&lt;/qty&gt; &lt;price&gt;1500.00&lt;/price&gt; &lt;extended&gt;3000.00&lt;/extended&gt; &lt;/item&gt; </code></pre> <p>The closing <code>&gt;</code> turns into <code>&amp;gt;</code> and the XML does not validate. Can someone help me fix this problem?</p> <p>Thanks!</p> <p>EDIT: Here is the whole function that generates the XML. I only call and print this function. There is nothing done to the string that is invalidating it.</p> <pre><code>function build_xml($p, $c) { global $wpdb; // Make the billing and shipping data available $this-&gt;determine_shipping_details($p, $c); $this-&gt;determine_billing_details($p, $c); // Build the XML $xml = '&lt;?xml version="1.0" ?&gt; &lt;orderdata batch="'.$p['id'].'"&gt; &lt;order id="'.$p['id'].'"&gt; &lt;orderdate&gt;'.date('m/d/Y h:i:s', $p['date']).'&lt;/orderdate&gt; &lt;store&gt;'.$this-&gt;store_id.'&lt;/store&gt; &lt;adcode&gt;OL&lt;/adcode&gt; &lt;username&gt;'.$this-&gt;username.'&lt;/username&gt; &lt;password&gt;'.$this-&gt;password.'&lt;/password&gt; &lt;billingaddress&gt; &lt;firstname&gt;'.$this-&gt;billing_details['first_name'].'&lt;/firstname&gt; &lt;lastname&gt;'.$this-&gt;billing_details['last_name'].'&lt;/lastname&gt; &lt;address1&gt;'.$this-&gt;billing_details['address'].'&lt;/address1&gt; &lt;city&gt;'.$this-&gt;billing_details['city'].'&lt;/city&gt; &lt;state&gt;'.$this-&gt;billing_details['state'].'&lt;/state&gt; &lt;zipcode&gt;'.$this-&gt;billing_details['zip'].'&lt;/zipcode&gt; &lt;country&gt;'.$this-&gt;billing_details['country'].'&lt;/country&gt; &lt;phone&gt;'.$this-&gt;billing_details['phone'].'&lt;/phone&gt; &lt;email&gt;'.$this-&gt;billing_details['email'].'&lt;/email&gt; &lt;/billingaddress&gt; &lt;shippingaddress&gt; &lt;firstname&gt;'.$this-&gt;shipping_details['first_name'].'&lt;/firstname&gt; &lt;lastname&gt;'.$this-&gt;shipping_details['last_name'].'&lt;/lastname&gt; &lt;address1&gt;'.$this-&gt;shipping_details['address'].'&lt;/address1&gt; &lt;city&gt;'.$this-&gt;shipping_details['city'].'&lt;/city&gt; &lt;state&gt;'.$this-&gt;shipping_details['state'].'&lt;/state&gt; &lt;zipcode&gt;'.$this-&gt;shipping_details['zip'].'&lt;/zipcode&gt; &lt;country&gt;'.$this-&gt;shipping_details['country'].'&lt;/country&gt; &lt;phone&gt;'.$this-&gt;shipping_details['phone'].'&lt;/phone&gt; &lt;email&gt;'.$this-&gt;shipping_details['email'].'&lt;/email&gt; &lt;/shippingaddress&gt; &lt;orderdetails&gt;'; // Add the individual items' information to the XML $i = 1; foreach($c as $key =&gt; $value) { $xml .= '&lt;item number="'.$i.'"&gt; &lt;sku&gt;'.$this-&gt;get_product_sku($key, $value).'&lt;/sku&gt; &lt;description&gt; &lt;![CDATA[ '.get_the_title($value['prodid']).' ]]&gt; &lt;/description&gt; &lt;qty&gt;'.$value['quantity'].'&lt;/qty&gt; &lt;price&gt;'.$value['price'].'&lt;/price&gt; &lt;extended&gt;'.str_replace(stripslashes( get_option('wpsc_thousands_separator') ), '', trim(wpsc_currency_display($value['quantity']*$value['price'], array('display_currency_symbol' =&gt; false, 'display_decimal_point' =&gt; true, 'display_currency_code' =&gt; false, 'display_as_html' =&gt; false)))).'&lt;/extended&gt; &lt;/item&gt;'; $i++; } // Add the order totals $xml .= '&lt;subtotal&gt;'.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' =&gt; false, 'display_decimal_point' =&gt; true, 'display_currency_code' =&gt; false, 'display_as_html' =&gt; false)))).'&lt;/subtotal&gt; &lt;shipping code="'.'FEG'.'" rate="'.$p['base_shipping'].'" thirdparty=""&gt;'.'FEDEX GROUND SERVICE'.'&lt;/shipping&gt; &lt;tax rate="'.$p['wpec_taxes_rate'].'"&gt;'.$p['wpec_taxes_total'].'&lt;/tax&gt; &lt;total&gt;'.$p['totalprice'].'&lt;/total&gt; &lt;amountpaid&gt;'.$p['totalprice'].'&lt;/amountpaid&gt; &lt;/orderdetails&gt;'; // Close out the tags $xml .= '&lt;/order&gt; &lt;/orderdata&gt;'; return $xml; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload