简体   繁体   English

如何转义html标签? 在json中从phonegap android中的php检索

[英]How to escape html tags ? in json retrived from php in phonegap android

I creating an app in which I'm using php in server side.When an Ajax call is made its calling an php to retrieve the data from the table but the issue is some table contains html & special characters tags so i get an error in the Ajax : 我创建了一个我在服务器端使用php的应用程序。当进行Ajax调用时,它调用php从表中检索数据,但问题是某些表包含html和特殊字符标签,因此我收到错误消息Ajax:

05-31 00:59:07.670: D/CordovaLog(872): Server is not responding... Please try again: SyntaxError: Unexpected token <
05-31 00:59:07.670: I/chromium(872): [INFO:CONSOLE(342)] "Server is not responding... Please try again: SyntaxError: Unexpected token <", source: file:///android_asset/www/home.html (342)

can any tell how to solve this issue. 谁能说出如何解决这个问题。 Thanks in advance. 提前致谢。

you may use escapeHtml which Returns an HTML escaped representation of the given plain text. 您可以使用escapeHtml ,它返回给定纯文本的HTML转义表示。 For more info see at escapeHtml 有关更多信息,请参见scapeHtml

Or you may use TextUtils.htmlEncode("your json tag") to encode html. 或者,您可以使用TextUtils.htmlEncode("your json tag")对html进行编码。

Edit 编辑
As you are using phonegap so you may use htmlencoding is PHP also as 当您使用phonegap时 ,您可能会使用htmlencodingPHP也是如此

htmlentities($str, ENT_QUOTES);

For more information see at htmlentities in PHP 有关更多信息,请参见PHP中的htmlentities。

To encode html in php and decode back in your app,you may refer this link 要在php中编码html并在您的应用中解码回来,您可以参考此链接
Using PHP's JSON encode and decode functions to handle data sent to and from your app 使用PHP的JSON编码和解码功能来处理与您的应用之间发送和发送的数据

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

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