简体   繁体   中英

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 :

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. For more info see at escapeHtml

Or you may use TextUtils.htmlEncode("your json tag") to encode html.

Edit
As you are using phonegap so you may use htmlencoding is PHP also as

htmlentities($str, ENT_QUOTES);

For more information see at htmlentities in PHP

To encode html in php and decode back in your app,you may refer this link
Using PHP's JSON encode and decode functions to handle data sent to and from your app

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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