简体   繁体   English

html符号已被javascript中的ASCII代码取代

[英]html symbols are getting replaced by ascii codes in javascript

I am having a php string in the following format: 我有以下格式的php字符串:

<pre>
$configOptions = "vCPUCores : '1 vCPU $3.00AUD',Ram : '0.5 GB $10.00AUD',PrimaryDrive : '50GB',DriveIOPs : '100'";
</pre>

I need to pass this string to analytics using javascript. 我需要使用javascript将此字符串传递给分析。

  <script>
           var configOptions = <?php echo $configOptions; ?>;
    </scrip>

However, when the data is passed to analytics, the single quotes are replaced by the corresponding ascii codes -&#039; 但是,当数据传递到分析时,单引号被相应的ASCII代码-&#039;代替。

The output is obtained in the following format: 以以下格式获得输出:

var configOptions = vCPUCores : '1 vCPU3.00AUD',Ram : '0.5 GB10.00AUD',PrimaryDrive : \'50GB\'

Here all the single quotes have got replaced ( when viewed through the browser source). 在这里,所有单引号都已替换(通过浏览器源查看时)。 This doesn't occur if I print the same in php. 如果在php中打印相同的内容,则不会发生这种情况。 The issue occurs when the php data is passed to javascript. 当php数据传递到javascript时,会发生此问题。

I have tried several javascript and php encoding techniques regarding this, But none of them work. 我已经尝试了几种与此有关的javascript和php编码技术,但是它们都不起作用。

Can anyone help me to fix this issue. 谁能帮我解决此问题。

Try this: 尝试这个:

<script>
       var configOptions = <?php echo urlencode($configOptions); ?>;
</scrip>

or 要么

<script>
       var configOptions = <?php echo rawurlencode($configOptions); ?>;
</scrip>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM