我正在尝试将一些xml数据传递给PHP变量,然后在javascript图表中使用
我的字符串变量如下:
$temp = '<chart manageResize="1" dateFormat="dd/mm/yyyy" ganttLineColor="CCCCCC" ganttLineAlpha="20" gridBorderAlpha="20" showTaskNames="1" hoverCapBgColor="F1F1F1" hoverCapBorderColor="333333" paletteThemeColor="333333" hoverBandColor="3d3d3d" hoverBandAlpha="95" showGanttPaneHorizontalHoverBand="0" showGanttPaneVerticalHoverBand="0">\n\
<categories bgColor="333333" baseFont="Arial" baseFontCOlor="FFFFFF" baseFontSize="12" showhoverband="0" >\n\
<category start="1/1/2005" end="31/5/2005" align="center" name="Sales Territory Assignment" fontColor="ffffff" isBold="1" fontSize="16" />\n\
</categories>\n\
<categories font="Arial" fontColor="ffffff" isBold="1" fontSize="12" bgColor="333333">\n\
<category start="1/1/2005" end="31/1/2005" name="January" />\n\
<category start="1/2/2005" end="28/2/2005" name="February" />\n\
<category start="1/3/2005" end="31/3/2005" name="March" />\n\
<category start="1/4/2005" end="30/4/2005" name="April"/>\n\
<category start="1/5/2005" end="31/5/2005" name="May" />\n\
</categories>\n\
<processes headerbgColor="333333" fontColor="ffffff" fontSize="12" bgColor="333333" align="right" >\n\
<process Name="Tom" id="1" />\n\
<process Name="Harry" id="2" />\n\
<process Name="Mary" id="4" />\n\
<process Name="Mike" id="3" />\n\
</processes>\n\
<tasks color="" alpha="" font="" fontColor="" fontSize="" isAnimated="1">\n\
<task name="North" processId="1" start="3/1/2005" end="4/2/2005" Id="1_1" color="e1f5ff" borderColor="AFD8F8"/>\n\
<task name="East" processId="1" start="6/2/2005" end="24/3/2005" Id="1_2" color="e1f5ff" borderColor="AFD8F8"/>\n\
<task name="Vacation" processId="1" start="25/3/2005" end="18/4/2005" Id="1_3" color="e1f5ff" borderColor="AFD8F8" height="2" showBorder="1" topPadding="49%"/>\n\
<task name="South" processId="1" start="18/4/2005" end="24/5/2005" Id="1_4" color="e1f5ff" borderColor="AFD8F8"/>\n\
<task name="South" processId="2" start="15/1/2005" end="5/3/2005" Id="2_1" color="F6BD0F" borderColor="F6BD0F"/>\n\
<task name="West" processId="2" start="21/3/2005" end="10/5/2005" Id="2_2" color="F6BD0F" borderColor="F6BD0F"/>\n\
<task name="Global" processId="3" start="7/1/2005" end="26/5/2005" Id="3_1" width="12" color="8BBA00" borderColor="8BBA00"/>\n\
<task name="South" processId="4" start="13/3/2005" end="19/4/2005" Id="4_1" width="12" color="FF654F" borderColor="FF654F" />\n\
</tasks>\n\
\n\
</chart>';
$xml = simplexml_load_string($temp, 'SimpleXMLElement', LIBXML_NOCDATA);//LIBXML_NOCDATA LIBXML_NOWARNING
// see object structure
print_r($xml);
现在,我希望将此孔字符串传递到我的图表中,但print语句显示此输出:
SimpleXMLElement对象([@attributes] =&gt;数组([manageResize] =&gt; 1 [dateFormat] =&gt; dd / mm / yyyy [ganttLineColor] =&gt; CCCCCC [ganttLineAlpha] =&GT; 20 [gridBorderAlpha] =&gt; 20 [showTaskNames] =&gt; 1 [hoverCapBgColor] =&gt; F1F1F1 [hoverCapBorderColor] =&gt; 333333 [paletteThemeColor] =&gt; 333333 [hoverBandColor] =&gt; 3d3d3d [hoverBandAlpha] =&gt; 95 [showGanttPaneHorizontalHoverBand] =&gt; 0 [showGanttPaneVerticalHoverBand] =&gt; 0)[类别] =&gt;数组([0] =&gt; \ n \ \ n \ [1] =&gt; \ n \ \ n \ \ n \ \ n \ \ n \ \ n \))[进程] =&gt; \ n \ \ n \ \ n \ n \ \ n \ \ n \ [tasks] =&gt; \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \)
丢弃了许多行而只是(\ n)而不是它们,我试图释放我的xml(\ n)
我尝试使用大量数据解析(LIBXML_PARSEHUGE),但不会影响任何内容 有什么想法吗?
答案 0 :(得分:0)
如果您想调试/转储SimpleXMLElement
,则不能print_r
它。
改为使用asXML()
:
echo $xml->asXML();
请注意,如果您想在浏览器中看到此输出,则需要将其与htmlentities()
一起打包。如果您希望输出包含换行符,请使用nl2br()
。
echo nl2br(htmlentities($xml->asXML()));