简体   繁体   English

编码的HTML字符串在CodeIgniter中未正确解码

[英]Encoded HTML string incorrectly decoded in CodeIgniter

I post data containing an html string as well as some other data from JavaScript to the PHP (Codeigniter) server w/ AJAX & JSON. 我将包含html字符串以及其他一些JavaScript数据的数据发布到带有AJAX和JSON的PHP(Codeigniter)服务器。

The HTML string contains an image tag w/ some style data. HTML字符串包含带有某些样式数据的图像标签。 On the server, the style info is gone! 在服务器上,样式信息不见了! The rest of the data I post is just fine. 我发布的其余数据都很好。

What should I do to the HTML string to prevent this? 我应该对HTML字符串采取什么措施来防止这种情况?

JavaScript side: JavaScript方面:

my_html='<p><img alt="" src="/ckfinder/userfiles/images/ferns.jpg" style="width: 200px; height: 133px;" /></p>';
my_count=1;

This is the data that gets posted in the AJAX call: 这是在AJAX调用中发布的数据:

form_data='my_html='+encodeURIComponent(my_html)+'&my_count='+my_count;

On the server: 在服务器上:

$html_str=$this->input->post('my_html');
$this->chromephp->log($html_str);

And this is what it prints: 这是它打印的内容:

<p><img alt="" src="/ckfinder/userfiles/images/ferns.jpg"  /></p>

EDIT - 1/24/18 After more investigation, it seems to be a decoding issue or the way I'm reading the value in Codeigniter (v 2). 编辑-1/24/18经过更多调查,这似乎是解码问题或我在Codeigniter(v 2)中读取值的方式。 Nothing to do with the fact it's an image tag. 它与图像标签无关。

Here's what I've figured out - 这是我想出来的-

Javascript: Javascript:

var hstr ='<p style="color:red;">Hello</p>';

After encodeURIComponent(), encoded string submitted as form data: 在encodeURIComponent()之后,将编码后的字符串作为表单数据提交:

%3Cp%20style%3D%22color%3Ared%3B%22%3EHello%3C%2Fp%3E

But, in the server: 但是,在服务器中:

The (URIencoded string being submitted as form data over AJAX: $html_str=$this->input->post('hstr'); $this->chromephp->log($html_str); (URI编码的字符串通过AJAX作为表单数据提交:$ html_str = $ this-> input-> post('hstr'); $ this-> chromephp-> log($ html_str);

yields: 产量:

<p >Hello</p>

On the server if I urldecode() the encoded string directly, 在服务器上,如果我直接urldecode()编码的字符串,

$xx=urldecode('%3Cp%20style%3D%22color%3Ared%3B%22%3EHello%3C%2Fp%3E');
$this->chromephp->log($xx);

yields: 产量:

<p style="color:red;">Hello</p>

So is it that Codeigniter (v2) decodes it when I use input->post()? 那么,当我使用input-> post()时,Codeigniter(v2)会对它进行解码吗? Is there a way to get the raw undecoded string? 有没有办法获取未解码的原始字符串?

Any suggestions? 有什么建议么?

Help! 救命! Please! 请!

Mmiz 米米兹

尝试

form_data='my_html='+encodeURI(my_html)+'&my_count='+my_count;

暂无
暂无

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

相关问题 `atob` 抛出“要解码的字符串没有正确编码” - `atob` throws “The string to be decoded is not correctly encoded” &#39;Window&#39;错误&#39;atob&#39;:要解码的字符串未正确编码 - Error 'atob' on 'Window': The string to be decoded is not correctly encoded 谷歌地图编码字符串显示不正确 - Google maps encoded string displaying incorrectly 如果包含Unicode字符,则PHP中的编码字符串无法在JavaScript中解码 - Encoded string in PHP can't be decoded in JavaScript if contains Unicode characters 更正编码错误的字符串(ASCII字符返回UTF-8) - Correcting incorrectly encoded string (ASCII characters back to UTF-8) 将html编码的字符串转换为数组 - Turn html encoded string into array 如何知道 URL 是否已解码/编码? - How to know if a URL is decoded/encoded? 尝试对已用Java编码的JS中的Base64进行解码时,出现“要解码的字符串未正确编码”错误 - “The string to be decoded is not correctly encoded ” error when trying to decode Base64 in JS which has been encoded in Java 当推入window.location.hash时,正确编码的字符串会被解码 - Correctly encoded string gets decoded when pushed into window.location.hash DOMException: 无法在 &#39;Window&#39; 上执行 &#39;atob&#39;:要解码的字符串未正确编码。 有效载荷大小有问题吗? - DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded. Payload size a problem?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM