0

我有一个嵌入在 XML 文档中的 CSV 字符串,这是使用 XML 的闪存图表所必需的。问题是图表通过 javascript 片段从 HTML 文件中获取设置,如下所示:

<script type="text/javascript">
        // <![CDATA[        
        var so = new SWFObject("/gr/amstock.swf", "line", "100%", "100%", "8", "#FFFFFF");
        //so.addVariable("path", "../amline/");
        so.addVariable("chart_settings", escape('<settings><number_format><thousands_separator></thousands_separator><decimals_separator><![CDATA[.]]></decimals_separator></number_format><number_format><thousands_separator></thousands_separator><decimals_separator><![CDATA[.]]></decimals_separator></number_format><redraw><![CDATA[true]]></redraw><data_sets><data_set did="0"><color><![CDATA[#00688B]]></color><csv><separator><![CDATA[,]]></separator><date_format><![CDATA[MM/DD/YYYY]]></date_format><data><![CDATA[03/29/09,0
03/30/09,0
03/31/09,0
04/01/09,0
04/02/09,0</data><columns>...

因此,显然换行符会破坏 javascript(由 PHP 变量回显)。无论如何要删除换行符(或至少停止破坏javascript的换行符),但仍然可以让闪存图表正确地将其读取为CSV文件。

4

2 回答 2

3

试试这个。如果它不起作用,我有另一个想法。

<?php

// assumes *nix style newlines
echo str_replace( "\n", "\\n", $jsCode );
于 2009-04-29T15:37:20.923 回答
0
stringObj.replace("\n","");

stringObj 在哪里

<script type="text/javascript">
        // <![CDATA[            
        var so = new SWFObject("/gr/amstock.swf", "line", "100%", "100%", "8", "#FFFFFF");
        //so.addVariable("path", "../amline/");
        so.addVariable("chart_settings", escape('<settings><number_format><thousands_separator></thousands_separator><decimals_separator><![CDATA[.]]></decimals_separator></number_format><number_format><thousands_separator></thousands_separator><decimals_separator><![CDATA[.]]></decimals_separator></number_format><redraw><![CDATA[true]]></redraw><data_sets><data_set did="0"><color><![CDATA[#00688B]]></color><csv><separator><![CDATA[,]]></separator><date_format><![CDATA[MM/DD/YYYY]]></date_format><data><![CDATA[03/29/09,0
03/30/09,0
03/31/09,0
04/01/09,0
04/02/09,0</data><columns>...
于 2009-04-29T15:37:43.010 回答