Jump to content

Recommended Posts

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.

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. 

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.

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. 

 

 

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

 

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.

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

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.

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

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.

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

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 &#123;).

After that's right, if you have problems then you need to deal with character encoding. That's specified in the


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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.