adrianTNT Posted July 24, 2008 Share Posted July 24, 2008 Hello. I have some issues understanding special characters and how they should be printed on screen. For example... php takes from database an image title and it is: "Brasão" with that special "a". In the web page it is printed correctly but inside an rss (feed file that I made) it says: The XML page cannot be displayed Reference to undefined entity 'Atilde'. Error processing resource 'http://www.jpgbox.com/feed.xml'. Line 76, Position 16 <title>Brasão Rio Grande do Sul</title> ---------------^ Is there a function that I can use to convert the string to be safely printed in the RSS file? In my rss header I have application/rss+xml charset:utf-8. I hope I explained correctly. Thank you. - Adrian. Quote Link to comment https://forums.phpfreaks.com/topic/116449-understanding-and-printingencoding-special-characters/ Share on other sites More sharing options...
effigy Posted July 24, 2008 Share Posted July 24, 2008 The data should be encoded in UTF-8 or the entities converted to their numerical equivalents, e.g., & # x e 3 ;. What character set is the database using? Quote Link to comment https://forums.phpfreaks.com/topic/116449-understanding-and-printingencoding-special-characters/#findComment-598818 Share on other sites More sharing options...
adrianTNT Posted July 24, 2008 Author Share Posted July 24, 2008 Hello, the tables show latin1_swedish_ci as "collation" and the same in an upper level; I don't know if is correct or not. (These should be the default values that php my admin shown me when setting the database). I later saw that I had an html_entities() done on the image_title and that was what caused the error I mentioned above in first post. I removed the html_entities() and did this: $image_title = strip_tags($image_title); $image_title = str_replace("\r\n"," ",$image_title); $image_title = utf8_encode($image_title); But when it reaches an '&' it says: Whitespace is not allowed at this location. Error processing resource 'feed.xml'. Line 1353, Positio... <description>Mother & daughter Golden Retriver's Molly & Elsie Do you know what I should do about this? Should I just str_replace the '&' with something like 'and' or there is a more professional fix to avoid this? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/116449-understanding-and-printingencoding-special-characters/#findComment-598872 Share on other sites More sharing options...
effigy Posted July 24, 2008 Share Posted July 24, 2008 How are you creating this file? Which XML functions? Quote Link to comment https://forums.phpfreaks.com/topic/116449-understanding-and-printingencoding-special-characters/#findComment-598880 Share on other sites More sharing options...
adrianTNT Posted July 24, 2008 Author Share Posted July 24, 2008 I guess it's "manually" without XML functions ... I have: <?php header("content-type: application/rss+xml charset:utf-8",true);?> <?php echo html_entity_decode('<?xml version="1.0" encoding="utf-8" ?>');?> ... <?php echo "<title>".$listing_title."</title>\n";?> ... Quote Link to comment https://forums.phpfreaks.com/topic/116449-understanding-and-printingencoding-special-characters/#findComment-598885 Share on other sites More sharing options...
effigy Posted July 24, 2008 Share Posted July 24, 2008 I would imagine something like XMLWriter would handle the data properly. A user note states that the input must be UTF-8, though. See if MySQL will convert it for you via this method. Quote Link to comment https://forums.phpfreaks.com/topic/116449-understanding-and-printingencoding-special-characters/#findComment-598904 Share on other sites More sharing options...
adrianTNT Posted July 25, 2008 Author Share Posted July 25, 2008 I think with XMLWriter I would have to code the whole page differently. I tried some more things and it appears to work ok like this: $listing_title = $row_Recordset_listings_rss['listing_title']; $listing_title = strip_tags($listing_title); $listing_title = str_replace("\r\n"," ",$listing_title); $listing_title = htmlspecialchars($listing_title); $listing_title = utf8_encode($listing_title); Using htmlspecialchars to get rid of the errors generated by characters like "&". So apparently it works ok now. Thank you for your time. - Adrian. Quote Link to comment https://forums.phpfreaks.com/topic/116449-understanding-and-printingencoding-special-characters/#findComment-599111 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.