dmaxey Posted December 28, 2011 Share Posted December 28, 2011 If one inserts acute letters, grave letters, ampersands and accented letters in xhtml they show perfectly on the page. However if one uses insert or rss feed they show as � or a square. How does one make them show correctly. Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/ Share on other sites More sharing options...
ManiacDan Posted December 28, 2011 Share Posted December 28, 2011 Encode them properly with htmlentities Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1301962 Share on other sites More sharing options...
dmaxey Posted December 29, 2011 Author Share Posted December 29, 2011 I hope you mis-understood me or I am lost. When I write an insert I correctly code to show acute and grave accents and anything else for that matter. That shows perfectly. The problem arises with <?php $french= strftime("%A %d %B %Y - %H:%M",time()); echo $french; ?> Showing jeudi 29 d�cembre 2011 - 08:59 I have perused the link you gave but cannot see where I would implement it. I have no control over what php sends from <?php date_default_timezone_set('Europe/paris'); setlocale(LC_ALL, array('fr.UTF-8','fr_FR@euro','fr_FR','french')); ?> The rss feeds are feeds from other people and once again I have no control over their feed. Is there a way of using htmlentities to show the feeds correctly. once I receive them. I just need pointing in the right direction and dont mind messing but I would appreciate a valid pointer. Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302132 Share on other sites More sharing options...
ManiacDan Posted December 29, 2011 Share Posted December 29, 2011 Ok, back up. You're right, I'm not understanding, because now you've described four entirely separate methods of displaying. What is the exact problem? Where do you get the data from? How do you display it? When does the error appear? Do not tell me about echoing random things which may or may not work, do not tell me about setting locales, tell me the problem. Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302178 Share on other sites More sharing options...
dmaxey Posted December 29, 2011 Author Share Posted December 29, 2011 Thank you for bearing with me. I am not sure I can explain in any other way but here goes. strftime is something I have no control over, so should it be inserted in a formula to be changed by htmlentities? If so like what? The rss feeds are processed through xml, thus function render_products_from_RSS() { if ($xml = simplexml_load_file(STORE_XML_RSS_FILE)) { $output = "<table><tr>"; // sets loop to 0 $i = 0; // starts looping through products foreach ($xml->channel->item as $item) { $output .= ' <td style="border:none;"><h3 > <img src="images/headers/rss.png" width="68" height="67" alt="rss logo " style="float:left;"/>'. $item->title.'</h3> <p style="margin-bottom:0px;"> '. $item->description.'</p> <p><span style="font-size:8px;">'. $item->pubDate.'</span></p> </td> '; // checks the loop. If it's >= 2 (indicating that it's looped 3 times)... if ($i >= 0){ // start new row $output .= "</tr>"; // reset loop $i = 0; } // if not, add one to the loop else $i++; break; } // finishes table $output .= '</table>'; return $output; } else $output .= 'News cannot be displayed at this time.'; } ?> Should the htmlentities go here? Please advise in a manner I may understand. Kindest regards and thanks for the help so far. Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302239 Share on other sites More sharing options...
ManiacDan Posted December 29, 2011 Share Posted December 29, 2011 Except strftime doesn't exist in the code you gave. Again: Describe the problem. In English. "I get an RSS feed from someSite.com and run their timestamp through strftime but the output is garbled." <-- that is a problem description. Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302253 Share on other sites More sharing options...
Pikachu2000 Posted December 29, 2011 Share Posted December 29, 2011 And while you're at it, when posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302265 Share on other sites More sharing options...
dmaxey Posted December 29, 2011 Author Share Posted December 29, 2011 Right, forget the rss feeds. Just help me with a short bit of code . Above the head I have the following code which sets the setlocale. <?php require_once 'functions/functions.php'; ini_set('display_errors', 'Off'); ini_set('display_startup_errors', 'Off'); error_reporting(0); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <?php date_default_timezone_set('Europe/paris'); setlocale(LC_ALL, array('fr.UTF-8','fr_FR@euro','fr_FR','french')); ?> <head> Then in the body I have <?php $french= strftime("%A %d %B %Y - %H:%M",time()); echo $french; ?> which shows as jeudi 29 d�cembre 2011 - 19:36 I would like it to show as jeudi 29 décembre 2011 - 19:36 I am sure all this was in the first post however just the one question now so hope this simplifies the subject. Will you be able to advise? Kindest regards Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302275 Share on other sites More sharing options...
ManiacDan Posted December 29, 2011 Share Posted December 29, 2011 Ok so the question has nothing to do with RSS feeds or inserts then? Can't you see how we might be confused? You would, as I said in the very first post, wrap htmlentities() around $french: echo htmlentities($french); Done. Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302280 Share on other sites More sharing options...
dmaxey Posted December 29, 2011 Author Share Posted December 29, 2011 Thank you ever so much. That works exactly as you expected it would. So is the Rss feed an impossible conundrum or would you allow me to post the code, in the forum's . . . BBCode tags. For your perusal. Once again many thanks and kindest regards. Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302296 Share on other sites More sharing options...
ManiacDan Posted December 29, 2011 Share Posted December 29, 2011 You still have not described a problem relating to RSS feeds. Explain it the same way. Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302297 Share on other sites More sharing options...
dmaxey Posted December 29, 2011 Author Share Posted December 29, 2011 I will try and use the advice you have already given to try to sort out the inserts and rss feeds. If I fail I will post the code of only one problem. Kindest regards David Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302309 Share on other sites More sharing options...
dmaxey Posted December 29, 2011 Author Share Posted December 29, 2011 Following your advice I got inserts working but have struggled with rss feeds. so here is the code to print the rss. <?php define('STORE_XML_RSS_FILE' , htmlentities('http://www.computerweekly.com/feed/0ac94b78-3177-43d3-936c-ae5e60aaa69d/CW360/The-latest-IT-News-headlines.xml')); require_once(($_SERVER['DOCUMENT_ROOT'] .'/functions/templates.php')); /** Functions **/ function get_xml_rss() {return new SimpleXMLelement(file_get_contents(STORE_XML_RSS_FILE));} ?> <?php function render_products_from_RSS() { if ($xml = simplexml_load_file(STORE_XML_RSS_FILE)) { $output = "<table><tr>"; // sets loop to 0 $i = 0; // starts looping through products foreach ($xml->channel->item as $item) { $output .= ' <td style="border:none;"><h3 > <img src="images/headers/rss.png" width="68" height="67" alt="rss logo " style="float:left;"/>'. $item->title.'</h3> <p style="margin-bottom:0px;"> '. $item->description.'</p> <p><span style="font-size:8px;">'. $item->pubDate.'</span></p> </td> '; // checks the loop. If it's >= 2 (indicating that it's looped 3 times)... if ($i >= 0){ // start new row $output .= "</tr>"; // reset loop $i = 0; } // if not, add one to the loop else $i++; break; } // finishes table $output .= '</table>'; return $output; } else $output .= 'News cannot be displayed at this time.'; } ?> and finally <?php echo render_products_from_RSS();?> [/code Kindest regards Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302349 Share on other sites More sharing options...
ManiacDan Posted December 29, 2011 Share Posted December 29, 2011 Ok, are you saying that you're trying to FETCH an RSS feed and output portions of that RSS feed as HTML? because you're not printing RSS, you're printing HTML. that being said, see all those places you get information from your SimpleXMLObject elements? $item->description? Put htmlentities around that. Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302351 Share on other sites More sharing options...
dmaxey Posted December 29, 2011 Author Share Posted December 29, 2011 Doing nothing this is shown, With cloud computing, as with data breaches, it is a question of âwhenâ not âifâ, so what can information security professionals do practically to manage security compliance in the cloud? When I put <p style="margin-bottom:0px;"> '.htmlentities($item->description ).'</p> I get With cloud computing, as with data breaches, it is a question of âÂ�Â�whenâÂ�Â� not âÂ�Â�ifâÂ�Â�, so what can information security professionals do practically to manage security compliance in the cloud? So where do I put the echo htmlentities() Bed now will try again tomorrow. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302363 Share on other sites More sharing options...
ManiacDan Posted December 30, 2011 Share Posted December 30, 2011 Looks like the data is already corrupt when you pull it from the source. Check the source in your browser, is it screwed up there? (What I mean is: Go to the XML feed in your browser without involving your code at all) Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302534 Share on other sites More sharing options...
dmaxey Posted December 30, 2011 Author Share Posted December 30, 2011 Tried for several hours and tried many different inserts but the best I get by $output .= ' <td style="border:none;"><h3 > <img src="images/headers/rss.png" width="68" height="67" alt="rss logo " style="float:left;"/>'. $item->title.'</h3> <p style="margin-bottom:0px;">'. htmlentities( $item->description). '</p> <p><span style="font-size:8px;">'. $item->pubDate.'</span></p> </td> '; // checks the loop. If it's >= 2 (indicating that it's looped 3 times)... if ($i >= 0){ // start new row $output .= "</tr>"; // reset loop $i = 0; } // if not, add one to the loop else $i++; break; } // finishes table $output .= '</table>'; return htmlentities($output); Shows all the table parts and more rubbish. I am echoing all the table so understand this what I dont understand is where I should do the echo of htmlentities() This problem occurs very rarely so I understand I must put up with it. Very irritating. Thanks again for your help. Happy New Year to you and yours. Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302597 Share on other sites More sharing options...
dmaxey Posted December 30, 2011 Author Share Posted December 30, 2011 Just seen your previous post. went to the feed as in the define('STORE_XML_RSS_FILE' , htmlentities('http://www.computerweekly.com/feed/0ac94b78-3177-43d3-936c-ae5e60aaa69d/CW360/The-latest-IT-News-headlines.xml')); Browser shows this With cloud computing, as with data breaches, it is a question of “when” not “if”, so what can information security professionals do practically to manage security compliance in the cloud? source shows this. <description><![CDATA[With cloud computing, as with data breaches, it is a question of “when” not “if”, so what can information security professionals do practically to manage security compliance in the cloud?]]></description> Kindest regards Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302601 Share on other sites More sharing options...
requinix Posted December 30, 2011 Share Posted December 30, 2011 That output you posted looks like it was UTF-8 encoded twice. Okay. The RSS feed is probably in UTF-8 form. As long as your HTML output is also UTF-8, whether that's through a header header("Content-Type: text/html; charset=utf-8"); or a META tag you shouldn't need to do anything else with the text. Problems arise when the input and output aren't in the same encoding, or something tries to change the encoding of the data while it's in transit (such as a utf8_encode() when it's not needed). So theoretically, all you need is to have the RSS's encoding match the HTML page's encoding. Separately, don't use htmlentities() for that STORE_XML_RSS_FILE. It's only needed when outputting to HTML. It's unlikely that the URL would contain anything that would be entity-ized (as it would be an invalid URL to begin with) but still, isn't needed. And a slight correction to something Dan said earlier. ...Kinda. The whole thing was a bit vague. When putting text into RSS use htmlspecialchars, not htmlentities(). The difference is that the latter will try to encode some characters into HTML entities, but XML does not support those same entities. That is, things like "é" in XML are generally invalid. The former will only encode the characters that are strictly necessary: ampersands, less-thans, greater-thans, and double quotes. Plain XML only supports those four and numeric entities (like {). After that's right, if you have problems then you need to deal with character encoding. That's specified in the Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302635 Share on other sites More sharing options...
dmaxey Posted December 30, 2011 Author Share Posted December 30, 2011 The coding on the rss feed is <?xml version="1.0" encoding="ISO-8859-1" ?> I have no control over that. My page that shows the feed has <meta http-equiv="content-type" content="text/html; charset=utf-8" /> My xml feeds read <?xml version="1.0" encoding="UTF-8"?> The problematic part is the double quotes which look like the traditional 66 99 Hope they put a new feed on soon and then everything will be ok. Only happens occassionaly Regards Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302652 Share on other sites More sharing options...
requinix Posted December 30, 2011 Share Posted December 30, 2011 You can use iconv() or the mbstring extension to convert between text encodings. Get the strings from the RSS feed, as you normally would, but convert them to UTF-8 before you do anything else. Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302697 Share on other sites More sharing options...
dmaxey Posted December 31, 2011 Author Share Posted December 31, 2011 Eureka. got it showing correctly. i replaced, <p style="margin-bottom:0px;">'. $item->description . '</p> with. <p style="margin-bottom:0px;">'.iconv ( 'UTF-8', 'ISO-8859-1', $item->description ). '</p> So to my untrained eye it looks like I have converted the feed back to the ISO original. The quotation marks show as 66 99 so pleased. Thank you all for the helpful advice and Happy New Year to you all. From a 63 year old php newbie. Quote Link to comment https://forums.phpfreaks.com/topic/253971-inserts-and-rss-feeds/#findComment-1302805 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.