When i tried to display a JSON decoded response i got this JSON. But it returned invalid format.
I tried the same in http://www.jsoneditoronline.org/ and it also returned error.
Why is this error happening even if i tried to add addslashes() and htmlspecialchars function...
Any help is appreciated......
{"data":[{"id":"ZGRlBQR9ac3K","type":1,"title":"asasasas edieddddd","feed":{"is_img":0},"c_date":"2014-04-24 10:22:14","owner":"Joffin Joy","owner_first":"Joffin","owner_id":"ZGN0AQZ9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGN0AQZ9ac3K\/1\/small\/10443_1395738251_usr_crop.jpg","lc_cnt":[{"like":"1","comment":"6"}],"ckt_name":{"ZwVk":"Trainees"},"comments":{"ZwVk":[{"uc_id":"AQp1AN=9ac3K","uc_c_date":"2014-04-24 10:26:57","uc_m_date":"0000-00-00 00:00:00","comment":"dfdfdfdf","comment_type":"1","sender_type":"0","user_id":"ZGN0AQZ9ac3K","display_name":"Joffin Joy","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGN0AQZ9ac3K\/1\/small\/10443_1395738251_usr_crop.jpg","like_cnt":"1"}]}},{"id":"ZGNkZwN9ac3K","type":6,"title":"tlk","desc":"sdfsdfsdf","c_date":"2014-04-23 20:28:27","author_name":"Herald Charley","about_author":"sdfsdfsdf","authorId":"ZGNjAmD9ac3K","owner_first":"Sanesh","owner":"Sanesh Sunny","owner_id":"ZGNjBQN9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjBQN9ac3K\/1\/small\/noimage-ind.jpg","author_photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjAmD9ac3K\/1\/small\/10074_1398168441_usr_lr.","lc_cnt":[{"like":"0","comment":"5"}],"ckt_name":{"ZwVk":"Trainees"},"comments":{"ZwVk":[{"uc_id":"AQp1BD=9ac3K","uc_c_date":"2014-04-24 19:23:15","uc_m_date":"0000-00-00 00:00:00","comment":"testing...","comment_type":"1","sender_type":"0","user_id":"ZGNkZwH9ac3K","display_name":"User Jolly","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNkZwH9ac3K\/1\/small\/10125_1398517242_usr_crop.JPG","like_cnt":"0"},{"uc_id":"AQp2Aj=9ac3K","uc_c_date":"2014-04-25 12:48:41","uc_m_date":"0000-00-00 00:00:00","comment":"<script>alert('asdasdas')<\/script>","comment_type":"1","sender_type":"0","user_id":"ZGNkZwH9ac3K","display_name":"User Jolly","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNkZwH9ac3K\/1\/small\/10125_1398517242_usr_crop.JPG","like_cnt":"0"},{"uc_id":"AQp3Aj=9ac3K","uc_c_date":"2014-04-27 19:45:05","uc_m_date":"2014-04-27 19:45:32","comment":"test comment123456789","comment_type":"1","sender_type":"0","user_id":"ZGNjAGx9ac3K","display_name":"Arungopan Gopakumar","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjAGx9ac3K\/1\/small\/10059_1398933445_usr_crop.jpg","like_cnt":"1"}]}},{"id":"ZGNlBGD9ac3K","type":7,"title":"jkhkhjk df sdfsdfdsfdsfsfdsf","source":"http:\/\/www.lipsum.com\/feed\/htmlhttp:\/\/www.lipsum.com\/feed\/htmlhttp:\/\/www.lipsum.com\/feed\/htmlhttp:\/\/www.lipsum.com\/feed\/htmlhttp:\/\/www.lipsum.com\/feed\/htmlhttp:\/\/www.lipsum.com\/feed\/html","c_date":"2014-04-22 12:53:17","summary":"","owner_first":"Joffin","owner":"Joffin Joy","owner_id":"ZGN0AQZ9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGN0AQZ9ac3K\/1\/small\/10443_1395738251_usr_crop.jpg","lc_cnt":[{"like":"0","comment":"7"}],"ckt_name":{"ZwVk":"Trainees"},"comments":{"ZwVk":[{"uc_id":"AQL2Aj=9ac3K","uc_c_date":"2014-04-22 13:07:42","uc_m_date":"0000-00-00 00:00:00","comment":"<script>alert('asdsadasdsa'"'''")<\/script>","comment_type":"1","sender_type":"0","user_id":"ZGNkZwH9ac3K","display_name":"User Jolly","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNkZwH9ac3K\/1\/small\/10125_1398517242_usr_crop.JPG","like_cnt":"0"},{"uc_id":"AQL2BN=9ac3K","uc_c_date":"2014-04-22 13:08:09","uc_m_date":"0000-00-00 00:00:00","comment":"<script>alert('asdsadasdsa')<\/script>","comment_type":"1","sender_type":"0","user_id":"ZGNkZwH9ac3K","display_name":"User Jolly","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNkZwH9ac3K\/1\/small\/10125_1398517242_usr_crop.JPG","like_cnt":"0"},{"uc_id":"AQL2BD=9ac3K","uc_c_date":"2014-04-22 13:10:06","uc_m_date":"0000-00-00 00:00:00","comment":"<script>alert('helloooo checking....');<\/script>","comment_type":"1","sender_type":"0","user_id":"ZGNkZwH9ac3K","display_name":"User Jolly","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNkZwH9ac3K\/1\/small\/10125_1398517242_usr_crop.JPG","like_cnt":"0"}]}},{"id":"ZGRlZGL9ac3K","type":1,"title":"sample postApr 21 22014...edited sxdsdasdasdasdasdasdd\r\n\r\nLorem ipsum .","feed":{"is_img":0},"c_date":"2014-04-21 17:19:19","owner":"Joffin Joy","owner_first":"Joffin","owner_id":"ZGN0AQZ9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGN0AQZ9ac3K\/1\/small\/10443_1395738251_usr_crop.jpg","lc_cnt":null,"ckt_name":{"ZwVk":"Trainees"}},{"id":"ZGNlZGD9ac3K","type":2,"title":"sample event Apr 21 2014.....","desc":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas adipiscing diam elit, ac pharetra magna rhoncus id. Quisque placerat imperdiet dolor in varius.","st_date":"Apr 21, 2014","st_time":"20:30:00","end_date":"May 14, 2014","end_time":"15:00:00","location":"Long Beach, CA, United States","c_date":"2014-04-21 17:15:10","owner_first":"Joffin","owner":"Joffin Joy","owner_id":"ZGN0AQZ9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGN0AQZ9ac3K\/1\/small\/10443_1395738251_usr_crop.jpg","lc_cnt":null,"ckt_name":{"ZwVk":"Trainees"}},{"id":"ZGNkBQx9ac3K","type":2,"title":"evnt on 17th april(edited)","desc":"description field\r\n~!##$%^&*()_+\/\\'"\u3053\u3093\u306b\u3061\u306fHallå\u4f60\u597d\u0928\u092e\u0938\u094d\u0924\u0947\r\nalert('hello");","st_date":"Jan 02, 2010","st_time":"10:05:00","end_date":"Apr 17, 2014","end_time":"10:05:00","location":"Mobile, AL, United States","c_date":"2014-04-17 10:05:28","owner_first":"Sanesh","owner":"Sanesh Sunny","owner_id":"ZGNjBQN9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjBQN9ac3K\/1\/small\/noimage-ind.jpg","lc_cnt":[{"like":"1","comment":"3"}],"ckt_name":{"ZwVk":"Trainees"},"comments":{"ZwVk":[{"uc_id":"AQLjZD=9ac3K","uc_c_date":"2014-04-17 11:07:42","uc_m_date":"0000-00-00 00:00:00","comment":"sdsds","comment_type":"1","sender_type":"0","user_id":"ZGR9ac3K","display_name":"User User Technologies Pvt Ltd","u_type":"D09F","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGR9ac3K\/1\/small\/1398519087_11.jpg","like_cnt":"0"},{"uc_id":"AQLkZN=9ac3K","uc_c_date":"2014-04-17 11:44:35","uc_m_date":"0000-00-00 00:00:00","comment":"sdfsdfsdfsdf","comment_type":"1","sender_type":"0","user_id":"ZGNjAmD9ac3K","display_name":"Herald Charley","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjAmD9ac3K\/1\/small\/10074_1398168441_usr_lr.","like_cnt":"0"},{"uc_id":"AQLkZD=9ac3K","uc_c_date":"2014-04-17 11:44:45","uc_m_date":"0000-00-00 00:00:00","comment":"sdfsdfsdfsdf","comment_type":"1","sender_type":"0","user_id":"ZGNjAmD9ac3K","display_name":"Herald Charley","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjAmD9ac3K\/1\/small\/10074_1398168441_usr_lr.","like_cnt":"0"}]}},{"id":"ZGRkAmN9ac3K","type":1,"title":"test post by sanesh on 16th april and shared with trainees ckt","feed":{"is_img":0},"c_date":"2014-04-16 14:10:56","owner":"Sanesh Sunny","owner_first":"Sanesh","owner_id":"ZGNjBQN9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjBQN9ac3K\/1\/small\/noimage-ind.jpg","lc_cnt":[{"like":"0","comment":"1"}],"ckt_name":{"ZwVk":"Trainees"}},{"id":"ZGRkAmD9ac3K","type":1,"title":"edited","feed":{"is_img":0},"c_date":"2014-04-16 14:21:23","owner":"Sanesh Sunny","owner_first":"Sanesh","owner_id":"ZGNjBQN9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjBQN9ac3K\/1\/small\/noimage-ind.jpg","lc_cnt":[{"like":"0","comment":"9"}],"ckt_name":{"ZwVk":"Trainees"},"comments":{"ZwVk":[{"uc_id":"AQH3BD=9ac3K","uc_c_date":"2014-04-16 15:31:41","uc_m_date":"0000-00-00 00:00:00","comment":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam et malesuada libero. In hac habitasse platea dictumst. ","comment_type":"1","sender_type":"0","user_id":"ZGNjBQN9ac3K","display_name":"Sanesh Sunny","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjBQN9ac3K\/1\/small\/noimage-ind.jpg","like_cnt":"0"},{"uc_id":"AQH4Aj=9ac3K","uc_c_date":"2014-04-16 18:42:38","uc_m_date":"0000-00-00 00:00:00","comment":"~!##$%^&*()_+\/\\'"\u3053\u3093\u306b\u3061\u306fHallå\u4f60\u597d\u0928\u092e\u0938\u094d\u0924\u0947","comment_type":"1","sender_type":"0","user_id":"ZGNjBQN9ac3K","display_name":"Sanesh Sunny","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjBQN9ac3K\/1\/small\/noimage-ind.jpg","like_cnt":"0"}]}},{"id":"ZGNjAmx9ac3K","type":6,"title":"Sample Talk Added Apr 14 2014.....","desc":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In posuere elit odio, vel interdum ligula pretium vitae. Praesent eu orci non ipsum euismod mollis. ","c_date":"2014-04-14 18:34:44","author_name":"Sanesh Sunny","about_author":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In posuere elit odio,","authorId":"ZGNjBQN9ac3K","owner_first":"Joffin","owner":"Joffin Joy","owner_id":"ZGN0AQZ9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGN0AQZ9ac3K\/1\/small\/10443_1395738251_usr_crop.jpg","author_photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjBQN9ac3K\/1\/small\/noimage-ind.jpg","lc_cnt":null,"ckt_name":{"ZwVk":"Trainees"}},{"id":"ZGRjAGR9ac3K","type":1,"title":"I amsdsdsdsdsd co-founder ofsdsdsds da","feed":{"is_img":0},"c_date":"2014-03-08 07:47:22","owner":"User Jolly","owner_first":"User","owner_id":"ZGNkZwH9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNkZwH9ac3K\/1\/small\/10125_1398517242_usr_crop.JPG","lc_cnt":[{"like":"1","comment":"0"}],"ckt_name":{"ZGD3AQZ9ac3K":"Vijayee Bhava"}},{"id":"ZGRjAQx9ac3K","type":1,"title":"Lessons on Self Development\r\nhttp:\/\/localhost\/files\/vijayeebhava\/2\/Vijayeebhava_Lessons_Self_development.pptx\r\n\r\nPrepared by: Sreeja - Phoenix team","feed":{"is_img":0},"c_date":"2014-03-09 10:26:18","owner":"Vijayee Bhava","owner_first":"Vijayee Bhava","owner_id":"AQL2ZwL9ac3K","owner_type":"D09F","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/AQL2ZwL9ac3K\/1\/small\/1394201730_46626.png","lc_cnt":[{"like":"1","comment":"0"}],"ckt_name":{"ZGD3AQH9ac3K":"Vijayee Bhava - II"}},{"id":"ZGNlAmL9ac3K","type":7,"title":"Key Lessons on LEADERSHIP","desc":"https:\/\/localhost\/files\/vijayeebhava\/2\/Vijayeebhava_Leadership_Key_Lessons.docx <\/a>","source":"","c_date":"2014-03-08 20:40:55","summary":"","owner_first":"Anaz","owner":"Anaz Kabeer","owner_id":"ZGNmZQH9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNmZQH9ac3K\/1\/small\/10305_1382457349_usr_lr.","lc_cnt":[{"like":"1","comment":"0"}],"ckt_name":{"ZGD3AQH9ac3K":"Vijayee Bhava - II"}},{"id":"ZGNlAmp9ac3K","type":7,"title":"Qualities of an Entrepreneur","desc":"https:\/\/localhost\/files\/vijayeebhava\/2\/Vijayeebhava_Key_Lessons_Qualities_Entrepreneur.docx <\/a>","source":"","c_date":"2014-03-08 20:41:37","summary":"","owner_first":"Anaz","owner":"Anaz Kabeer","owner_id":"ZGNmZQH9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNmZQH9ac3K\/1\/small\/10305_1382457349_usr_lr.","lc_cnt":[{"like":"1","comment":"0"}],"ckt_name":{"ZGD3AQH9ac3K":"Vijayee Bhava - II"}}],"tp_likes":"[id=\"tp_like_ZGNlAmL9ac3K_7_T\"],[id=\"tp_like_ZGNlAmp9ac3K_7_T\"],[id=\"tp_like_ZGRjAQx9ac3K_1_T\"],[id=\"tp_like_ZGRlBQR9ac3K_1_T\"]","cmnt_likes":"[id=\"tp_like_ZGRlBQR9ac3K_1_AQp1AN=9ac3K_C\"]","up_next":"2014-03-09 09:14:44","up_start":0,"up_end":"15"}
There is a lot of Javascript in that JSON, and the double quotes in the alert()'s are whats making it invalid.
Paste your string in there, it shows you everything that's invalid
http://jsonformatter.curiousconcept.com/#jsonformatter
For reference I removed all the invalid parts, this string is valid JSON
{"data":[{"id":"ZGRlBQR9ac3K","type":1,"title":"asasasas edieddddd","feed":{"is_img":0},"c_date":"2014-04-24 10:22:14","owner":"Joffin Joy","owner_first":"Joffin","owner_id":"ZGN0AQZ9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGN0AQZ9ac3K\/1\/small\/10443_1395738251_usr_crop.jpg","lc_cnt":[{"like":"1","comment":"6"}],"ckt_name":{"ZwVk":"Trainees"},"comments":{"ZwVk":[{"uc_id":"AQp1AN=9ac3K","uc_c_date":"2014-04-24 10:26:57","uc_m_date":"0000-00-00 00:00:00","comment":"dfdfdfdf","comment_type":"1","sender_type":"0","user_id":"ZGN0AQZ9ac3K","display_name":"Joffin Joy","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGN0AQZ9ac3K\/1\/small\/10443_1395738251_usr_crop.jpg","like_cnt":"1"}]}},{"id":"ZGNkZwN9ac3K","type":6,"title":"tlk","desc":"sdfsdfsdf","c_date":"2014-04-23 20:28:27","author_name":"Herald Charley","about_author":"sdfsdfsdf","authorId":"ZGNjAmD9ac3K","owner_first":"Sanesh","owner":"Sanesh Sunny","owner_id":"ZGNjBQN9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjBQN9ac3K\/1\/small\/noimage-ind.jpg","author_photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjAmD9ac3K\/1\/small\/10074_1398168441_usr_lr.","lc_cnt":[{"like":"0","comment":"5"}],"ckt_name":{"ZwVk":"Trainees"},"comments":{"ZwVk":[{"uc_id":"AQp1BD=9ac3K","uc_c_date":"2014-04-24 19:23:15","uc_m_date":"0000-00-00 00:00:00","comment":"testing...","comment_type":"1","sender_type":"0","user_id":"ZGNkZwH9ac3K","display_name":"User Jolly","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNkZwH9ac3K\/1\/small\/10125_1398517242_usr_crop.JPG","like_cnt":"0"},{"uc_id":"AQp2Aj=9ac3K","uc_c_date":"2014-04-25 12:48:41","uc_m_date":"0000-00-00 00:00:00","comment":"","comment_type":"1","sender_type":"0","user_id":"ZGNkZwH9ac3K","display_name":"User Jolly","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNkZwH9ac3K\/1\/small\/10125_1398517242_usr_crop.JPG","like_cnt":"0"},{"uc_id":"AQp3Aj=9ac3K","uc_c_date":"2014-04-27 19:45:05","uc_m_date":"2014-04-27 19:45:32","comment":"test comment123456789","comment_type":"1","sender_type":"0","user_id":"ZGNjAGx9ac3K","display_name":"Arungopan Gopakumar","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjAGx9ac3K\/1\/small\/10059_1398933445_usr_crop.jpg","like_cnt":"1"}]}},{"id":"ZGNlBGD9ac3K","type":7,"title":"jkhkhjk df sdfsdfdsfdsfsfdsf","source":"http:\/\/www.lipsum.com\/feed\/htmlhttp:\/\/www.lipsum.com\/feed\/htmlhttp:\/\/www.lipsum.com\/feed\/htmlhttp:\/\/www.lipsum.com\/feed\/htmlhttp:\/\/www.lipsum.com\/feed\/htmlhttp:\/\/www.lipsum.com\/feed\/html","c_date":"2014-04-22 12:53:17","summary":"","owner_first":"Joffin","owner":"Joffin Joy","owner_id":"ZGN0AQZ9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGN0AQZ9ac3K\/1\/small\/10443_1395738251_usr_crop.jpg","lc_cnt":[{"like":"0","comment":"7"}],"ckt_name":{"ZwVk":"Trainees"},"comments":{"ZwVk":[{"uc_id":"AQL2Aj=9ac3K","uc_c_date":"2014-04-22 13:07:42","uc_m_date":"0000-00-00 00:00:00","comment":"","comment_type":"1","sender_type":"0","user_id":"ZGNkZwH9ac3K","display_name":"User Jolly","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNkZwH9ac3K\/1\/small\/10125_1398517242_usr_crop.JPG","like_cnt":"0"},{"uc_id":"AQL2BN=9ac3K","uc_c_date":"2014-04-22 13:08:09","uc_m_date":"0000-00-00 00:00:00","comment":"","comment_type":"1","sender_type":"0","user_id":"ZGNkZwH9ac3K","display_name":"User Jolly","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNkZwH9ac3K\/1\/small\/10125_1398517242_usr_crop.JPG","like_cnt":"0"},{"uc_id":"AQL2BD=9ac3K","uc_c_date":"2014-04-22 13:10:06","uc_m_date":"0000-00-00 00:00:00","comment":"","comment_type":"1","sender_type":"0","user_id":"ZGNkZwH9ac3K","display_name":"User Jolly","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNkZwH9ac3K\/1\/small\/10125_1398517242_usr_crop.JPG","like_cnt":"0"}]}},{"id":"ZGRlZGL9ac3K","type":1,"title":"sample postApr 21 22014...edited sxdsdasdasdasdasdasdd\r\n\r\nLorem ipsum .","feed":{"is_img":0},"c_date":"2014-04-21 17:19:19","owner":"Joffin Joy","owner_first":"Joffin","owner_id":"ZGN0AQZ9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGN0AQZ9ac3K\/1\/small\/10443_1395738251_usr_crop.jpg","lc_cnt":null,"ckt_name":{"ZwVk":"Trainees"}},{"id":"ZGNlZGD9ac3K","type":2,"title":"sample event Apr 21 2014.....","desc":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas adipiscing diam elit, ac pharetra magna rhoncus id. Quisque placerat imperdiet dolor in varius.","st_date":"Apr 21, 2014","st_time":"20:30:00","end_date":"May 14, 2014","end_time":"15:00:00","location":"Long Beach, CA, United States","c_date":"2014-04-21 17:15:10","owner_first":"Joffin","owner":"Joffin Joy","owner_id":"ZGN0AQZ9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGN0AQZ9ac3K\/1\/small\/10443_1395738251_usr_crop.jpg","lc_cnt":null,"ckt_name":{"ZwVk":"Trainees"}},{"id":"ZGNkBQx9ac3K","type":2,"title":"evnt on 17th april(edited)","desc":"","st_date":"Jan 02, 2010","st_time":"10:05:00","end_date":"Apr 17, 2014","end_time":"10:05:00","location":"Mobile, AL, United States","c_date":"2014-04-17 10:05:28","owner_first":"Sanesh","owner":"Sanesh Sunny","owner_id":"ZGNjBQN9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjBQN9ac3K\/1\/small\/noimage-ind.jpg","lc_cnt":[{"like":"1","comment":"3"}],"ckt_name":{"ZwVk":"Trainees"},"comments":{"ZwVk":[{"uc_id":"AQLjZD=9ac3K","uc_c_date":"2014-04-17 11:07:42","uc_m_date":"0000-00-00 00:00:00","comment":"sdsds","comment_type":"1","sender_type":"0","user_id":"ZGR9ac3K","display_name":"User User Technologies Pvt Ltd","u_type":"D09F","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGR9ac3K\/1\/small\/1398519087_11.jpg","like_cnt":"0"},{"uc_id":"AQLkZN=9ac3K","uc_c_date":"2014-04-17 11:44:35","uc_m_date":"0000-00-00 00:00:00","comment":"sdfsdfsdfsdf","comment_type":"1","sender_type":"0","user_id":"ZGNjAmD9ac3K","display_name":"Herald Charley","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjAmD9ac3K\/1\/small\/10074_1398168441_usr_lr.","like_cnt":"0"},{"uc_id":"AQLkZD=9ac3K","uc_c_date":"2014-04-17 11:44:45","uc_m_date":"0000-00-00 00:00:00","comment":"sdfsdfsdfsdf","comment_type":"1","sender_type":"0","user_id":"ZGNjAmD9ac3K","display_name":"Herald Charley","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjAmD9ac3K\/1\/small\/10074_1398168441_usr_lr.","like_cnt":"0"}]}},{"id":"ZGRkAmN9ac3K","type":1,"title":"test post by sanesh on 16th april and shared with trainees ckt","feed":{"is_img":0},"c_date":"2014-04-16 14:10:56","owner":"Sanesh Sunny","owner_first":"Sanesh","owner_id":"ZGNjBQN9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjBQN9ac3K\/1\/small\/noimage-ind.jpg","lc_cnt":[{"like":"0","comment":"1"}],"ckt_name":{"ZwVk":"Trainees"}},{"id":"ZGRkAmD9ac3K","type":1,"title":"edited","feed":{"is_img":0},"c_date":"2014-04-16 14:21:23","owner":"Sanesh Sunny","owner_first":"Sanesh","owner_id":"ZGNjBQN9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjBQN9ac3K\/1\/small\/noimage-ind.jpg","lc_cnt":[{"like":"0","comment":"9"}],"ckt_name":{"ZwVk":"Trainees"},"comments":{"ZwVk":[{"uc_id":"AQH3BD=9ac3K","uc_c_date":"2014-04-16 15:31:41","uc_m_date":"0000-00-00 00:00:00","comment":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam et malesuada libero. In hac habitasse platea dictumst. ","comment_type":"1","sender_type":"0","user_id":"ZGNjBQN9ac3K","display_name":"Sanesh Sunny","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjBQN9ac3K\/1\/small\/noimage-ind.jpg","like_cnt":"0"},{"uc_id":"AQH4Aj=9ac3K","uc_c_date":"2014-04-16 18:42:38","uc_m_date":"0000-00-00 00:00:00","comment":"","comment_type":"1","sender_type":"0","user_id":"ZGNjBQN9ac3K","display_name":"Sanesh Sunny","u_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjBQN9ac3K\/1\/small\/noimage-ind.jpg","like_cnt":"0"}]}},{"id":"ZGNjAmx9ac3K","type":6,"title":"Sample Talk Added Apr 14 2014.....","desc":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In posuere elit odio, vel interdum ligula pretium vitae. Praesent eu orci non ipsum euismod mollis. ","c_date":"2014-04-14 18:34:44","author_name":"Sanesh Sunny","about_author":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In posuere elit odio,","authorId":"ZGNjBQN9ac3K","owner_first":"Joffin","owner":"Joffin Joy","owner_id":"ZGN0AQZ9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGN0AQZ9ac3K\/1\/small\/10443_1395738251_usr_crop.jpg","author_photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNjBQN9ac3K\/1\/small\/noimage-ind.jpg","lc_cnt":null,"ckt_name":{"ZwVk":"Trainees"}},{"id":"ZGRjAGR9ac3K","type":1,"title":"I amsdsdsdsdsd co-founder ofsdsdsds da","feed":{"is_img":0},"c_date":"2014-03-08 07:47:22","owner":"User Jolly","owner_first":"User","owner_id":"ZGNkZwH9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNkZwH9ac3K\/1\/small\/10125_1398517242_usr_crop.JPG","lc_cnt":[{"like":"1","comment":"0"}],"ckt_name":{"ZGD3AQZ9ac3K":"Vijayee Bhava"}},{"id":"ZGRjAQx9ac3K","type":1,"title":"Lessons on Self Development\r\nhttp:\/\/localhost\/files\/vijayeebhava\/2\/Vijayeebhava_Lessons_Self_development.pptx\r\n\r\nPrepared by: Sreeja - Phoenix team","feed":{"is_img":0},"c_date":"2014-03-09 10:26:18","owner":"Vijayee Bhava","owner_first":"Vijayee Bhava","owner_id":"AQL2ZwL9ac3K","owner_type":"D09F","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/AQL2ZwL9ac3K\/1\/small\/1394201730_46626.png","lc_cnt":[{"like":"1","comment":"0"}],"ckt_name":{"ZGD3AQH9ac3K":"Vijayee Bhava - II"}},{"id":"ZGNlAmL9ac3K","type":7,"title":"Key Lessons on LEADERSHIP","desc":"https:\/\/localhost\/files\/vijayeebhava\/2\/Vijayeebhava_Leadership_Key_Lessons.docx <\/a>","source":"","c_date":"2014-03-08 20:40:55","summary":"","owner_first":"Anaz","owner":"Anaz Kabeer","owner_id":"ZGNmZQH9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNmZQH9ac3K\/1\/small\/10305_1382457349_usr_lr.","lc_cnt":[{"like":"1","comment":"0"}],"ckt_name":{"ZGD3AQH9ac3K":"Vijayee Bhava - II"}},{"id":"ZGNlAmp9ac3K","type":7,"title":"Qualities of an Entrepreneur","desc":"https:\/\/localhost\/files\/vijayeebhava\/2\/Vijayeebhava_Key_Lessons_Qualities_Entrepreneur.docx <\/a>","source":"","c_date":"2014-03-08 20:41:37","summary":"","owner_first":"Anaz","owner":"Anaz Kabeer","owner_id":"ZGNmZQH9ac3K","owner_type":"FH5R","photo":"http:\/\/localhost\/4thUser_v4\/images\/getuserphoto\/ZGNmZQH9ac3K\/1\/small\/10305_1382457349_usr_lr.","lc_cnt":[{"like":"1","comment":"0"}],"ckt_name":{"ZGD3AQH9ac3K":"Vijayee Bhava - II"}}],"tp_likes":"[id=\"tp_like_ZGNlAmL9ac3K_7_T\"],[id=\"tp_like_ZGNlAmp9ac3K_7_T\"],[id=\"tp_like_ZGRjAQx9ac3K_1_T\"],[id=\"tp_like_ZGRlBQR9ac3K_1_T\"]","cmnt_likes":"[id=\"tp_like_ZGRlBQR9ac3K_1_AQp1AN=9ac3K_C\"]","up_next":"2014-03-09 09:14:44","up_start":0,"up_end":"15"}
nalert('hello");". The double quote seems to invalid everything after, no ?
EDIT: Ho, as bartek said in his edit, you should try jsonlint. Thanks for the info, bartek.
Related
I have problem with regex tag html. Any one please help me!
Thanks this is some case of me... I have search and think but not do it.
Case 1
// My input to regex
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit <br/><img src="img.jpg/> sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua<p>
// Out Put after regex
Lorem ipsum dolor sit amet, consectetur adipisicing elit <br/><img src="img.jpg/> sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua
Case 2
// My input to regex
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit</p>
// Out put after regex
Lorem ipsum dolor sit amet, consectetur adipisicing elit
Case 3
// My input to regex
<p><ul>...</ul><p>
//Out put after regex
NULL
I'm guessing something like this is what you're after (example in javascript).
function checkParagraph(str)
{
var result = str.match(/^<p>([^<].*[^>])<\/p>$/i);
if (result) return result[1];
else return null;
}
alert(checkParagraph("<p>Lorem ipsum <br/><img src=\"img.jpg\"/> magna aliqua</p>"));
alert(checkParagraph("<p>Lorem ipsum magna aliqua</p>"));
alert(checkParagraph("<p><img src=\"img.jpg\"/></p>"));
With the additional information about only allowing BR, IMG, A and IMG-inside-A tags, the regex is quite different:
function checkParagraph(str)
{
var result = str.match(/^<p>(([^<>]+|<br\/>|<img[^>]+>|<a[^>]+>[^<>]*<\/a>|<a[^>]+><img[^>]+><\/a>)*)<\/p>$/i);
if (result) return result[1];
else return null;
}
alert(checkParagraph("Lorem ipsum magna aliqua"));
alert(checkParagraph("<p>Lorem ipsum magna aliqua</p>"));
alert(checkParagraph("<p>Lorem ipsum <br/> magna aliqua</p>"));
alert(checkParagraph("<p>Lorem ipsum magna aliqua</p>"));
alert(checkParagraph("<p>Lorem ipsum <img src=\"img.jpg\"/> magna aliqua</p>"));
alert(checkParagraph("<p>Lorem ipsum <br/><img src=\"img.jpg\"/> magna aliqua</p>"));
alert(checkParagraph("<p><br/><img src=\"img.jpg\"/></p>"));
alert(checkParagraph("<p><span>magna</span> aliqua</p>"));
alert(checkParagraph("<p><span>magna</span> aliqua</p>"));
alert(checkParagraph("<p><br/><img src=\"img.jpg\"/><span>magna</span> aliqua</p>"));
Break-down of the regex:
/.../i -> case insensitive for upper and lower case tags
^<p>...<\/p>$ -> input is enclosed in P tag
(...) -> the capture group between the brackets will become result[1]
(...|...)* -> any number of the following options:
[^<>]+ -> option 1: any text without tags
<br\/> -> option 2: a BR tag
<img[^>]+> -> option 3: an IMG tag
<a[^>]+>[^<>]*<\/a> -> option 4: an A tag with text inside
<a[^>]+><img[^>]+><\/a> -> option 5: an A tag with an IMG tag inside
I'm not sure of the terminology so I apologize ahead of time.
I'm trying to create a PHP template engine that will query a string for <ZONE header> and </ZONE header> and it will pull everything in between and then run a php function to see if the header exists. If the header exists it will display what was in between, and if the header does not exists it will remove what was in between.
Here's an example:
$string = "
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<ZONE header><img src="images/header.jpg" /></ZONE header>
<p>Nam sollicitudin mattis nisi, eu convallis mi tincidunt vitae.</p>
";
The function would ideally remove <ZONE header><img src="images/header.jpg" /></ZONE header> then it will run the php function I've created header() which checks to see if the "header" exists in the database, and if it does, it will display everything inside <ZONE header></ZONE header> and if it doesn't it will remove it from the string.
If "header" exists:
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<img src="images/header.jpg" />
<p>Nam sollicitudin mattis nisi, eu convallis mi tincidunt vitae.</p>
If "header" does not exist:
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>Nam sollicitudin mattis nisi, eu convallis mi tincidunt vitae.</p>
Here is what I was working with but got stuck:
preg_match_all("|\<ZONE_header>(.*)\<\/ZONE_header>|isU", $string, $zone, PREG_SET_ORDER);
if (isset($zone) && is_array($zone)) {
foreach ($zone as $key => $zoneArray) {
if ($key == 0) {
$html = $zoneArray[1];
if ($html != "") {
if (header() != "") {
$html = str_replace($zoneArray[0], NULL, $html);
}
}
}
}
}
echo $html;
Any ideas, thoughts, suggestions?
Thank you for any and all help!
Note that I replace your header() function with get_header().
$string = preg_replace_callback('/<ZONE header>(.+)<\/ZONE header>/', 'replace_header', $string);
function replace_header($matches) {
return get_header() ? $matches[1] : '';
}
See documentation for preg_replace_callback.
Like this ?
$string = '
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<ZONE header><img src="images/header.jpg" /></ZONE header>
<p>Nam sollicitudin mattis nisi, eu convallis mi tincidunt vitae.</p>
';
$pattern="#<ZONE header[^>]*>(.+)</ZONE header>#iU";
preg_match_all($pattern, $string, $matches);
if (strlen($matches[0][0])==0){
$string=strip_tags($string,"<p>");
}
else{
$string=strip_tags($string,"<p><img>");
}
echo $string;
How would I use PHP's preg_replace() to return only the value inside the <h1> in the following string (it's HTML text loaded in a variable called $html):
<h1>I'm Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque tincidunt porttitor magna, quis molestie augue sagittis quis.</p>
<p>Pellentesque tincidunt porttitor magna, quis molestie augue sagittis quis. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
I've tried this: preg_replace('#<h1>([.*])</h1>.*#', '$1', $html), but to no avail. Am I regex-ing this correctly? And is there a better PHP function that I should be using instead of preg_replace?
Here is how you do it using preg_replace:
$header = preg_replace('/<h1>(.*)<\/h1>.*/iU', '$1', $html);
You can also use preg_match:
$matches = array();
preg_match('/<h1>(.*)</h1>.*/iU', $html, $matches);
print_r($matches);
([.*]) means dot OR astersk
What you need is (.*?), which means any amount of any characters ungreedy
or
([^<]*) - which means any amount of any characters but not <
If I fopen/fread a text file, then send the content in an email, the newlines in the text file do not appear in the email when it arrives.
For example, the text...
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Sed leo erat,
rutrum posuere justo.
... arrives in the email inbox as:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed leo erat, rutrum posuere justo.
I'm using this PHP code:
$fh = fopen($email_file,'r');
$message = fread($fh,filesize($email_file));
fclose($fh);
mail("email#example.com",$subject,$message,$headers);
//Assume each variable is declared and defined.
What am I missing?
Edit: I needed to change the header Content-Type from HTML for the text version. Thanks to Yzmir and Footie. Their questions / comments led me to the correct answer.
Try replacing the new lines with <br/> and let me know if this solves it.
If you can't do it for your files, do it in your code using:
$message = nl2br($message);
How could I convert everyting between a tag to html enities:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et dolore
magna aliquyam erat, sed diam voluptua.
<code class="highlight sql">
CREATE TABLE `comments`
</code>
<h1>Next step</h1>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et
dolore magna aliquyam erat, sed diam voluptua.
At vero eos et accusam et justo duo dolores et ea rebum.
<b>Stet clita kasd gubergren, no sea takimata sanctus</b> est Lorem
dolor sit amet. Lorem ipsum dolor sit amet, consetetur
sadipscing elitr, sed diam nonumy eirmod tempor invidunt
ut labore et dolore magna aliquyam erat, sed diam voluptua:
<code class="highlight php">
<?php
$host = "localhost";
?>
</code>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr.
Note: That example above is a string which I could convert in PHP.
This comes down to a regex for me. And before you start shouting it is possible to reliably match & replace subsets of html, as long as there are no nesting tags.
This is the easy way tbh. A regex to match a tag start till end and apply a function to the matches / encoding what we need and replacing it.
Heres the code:
<?php
$string = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et dolore
magna aliquyam erat, sed diam voluptua.
<code class="highlight sql">
CREATE TABLE `comments`&
</code>
<h1>Next step</h1>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et
dolore magna aliquyam erat, sed diam voluptua.
At vero eos et accusam et justo duo dolores et ea rebum.
<b>Stet clita kasd gubergren&, no sea takimata sanctus</b> est Lorem
dolor sit amet. Lorem ipsum dolor sit amet, consetetur
sadipscing elitr, sed diam nonumy " eirmod " tempor invidunt
ut labore et dolore magna aliq&uyam erat, sed diam voluptua:
<code class="highlight php">
<?php
* $host = "localhost";
?>&
</code>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr.';
echo preg_replace("/(<code[^>]*?>)(.*?)(<\/code>)/se", "
stripslashes('$1').
htmlentities(stripslashes('$2')).
stripslashes('$3')
", $string);
And heres a working testcase on codepad
http://codepad.org/MhKwfOQl
This will work as long as there are no nasty nested tags / corrupted html.
I would still advise you to try and make sure you save the data as you want to make it visible, encoded where needed.
If you want to replace between a different set of tags change the regex.
Update: It seemed that $host was being parsed by php... and ofrourse we don't want this. This happened because php evaluates the replacement string as php which then executes the given functions and inputs the found strings into those functions, and if that string is encapsulated by double qoutes it will parse those strings too... heh what a hassle.
And another problem then arises, php escapes single and double qoutes in matches so they won't generate parse errors, this ment that any qoutes in the matches had to be stripped from their slashes too... resulting in the pretty long replace string.
Although a regular expression or parser may give you a solution to this puzzle, I think you may be going about your goal the wrong way.
Taken from the comments below the question:
#Poru How is that string generated?
#Phil: Fetched from database. It's
the content of a tutorial. It's an own development "CMS".
If you are storing this string in a database, and it's function is to return HTML content, you should be storing the content ready to serve as HTML, which means you must escape the appropriate characters with their equivalent HTML entities.
This was the advice already offered to you in this question: https://stackoverflow.com/questions/7059776/include-source-code-in-html-valid/7059834
The characters that must be escaped are explained here (among other various references):
http://php.net/manual/en/function.htmlspecialchars.php
The translations performed are:
'&' (ampersand) becomes '&'
'"' (double quote) becomes '"' when ENT_NOQUOTES is not set.
"'" (single quote) becomes ''' only when ENT_QUOTES is set.
'<' (less than) becomes '<'
'>' (greater than) becomes '>'
If in fact this is the case, and this string is supposed to be HTML output and has no other function, it doesn't make any sense to save it as invalid HTML, or at least not what you intend it to be.
If you must store your code examples unescaped, consider a separate database table for these snippets, and simply run htmlspecialchars() on them before outputting it to the HTML document. You could even assign a language to each record, and use the appropriate syntax highlighting tool for each case automatically.
What you are attempting, in my opinion, is not the appropriate solution to this particular problem, in this context. Escaping the characters and having your HTML content ready to be output to screen in it's current form is the way to go.
$dom = new DOMDocument;
$dom->loadHTML(...);
$tags = $dom->getElementsByTagName('tag');
foreach($tags as $tag) {
$tag->nodeValue = htmlentities($tag->nodeValue);
}
$dom->saveHTML();