Doubts Php htmlentities

1

This is just the will to learn, I put into production a site that has been working for some time. and I noticed that 'utf8_encode' worked on localhost but does not work in production now. Implemented the htmlentities and the result was inverse, the localhost disappeared the date and the net is perfect. Can someone explain why?

On the left is on the remote server and on the right is in place: Although the script used is the same.

Thisishowthebandwagonlooks:

<divid="news">
        <?php foreach ($articles as $article) { ?>
        <div><h2><?php echo $article['article_title']; ?></h2><br><span id="date">Publicado 
                <?php
                    setlocale(LC_ALL, 'pt_BR.utf8', 'Portuguese_Brazil');
                    //setlocale(LC_ALL, NULL);
                    date_default_timezone_set('Europe/Lisbon');

                    $uppercaseMonth = ucfirst(gmstrftime('%B'));
                    echo htmlentities(strftime( '%a, '.$uppercaseMonth.' %d de %Y'/* - %H:%M'*/, $article['article_timestamp']));
                ?></span><p><?php echo $article['article_content']; ?><br><br><span id="print"><a onclick="javascript:window.print();" href="#">Imprimir</a></span><span id="link"><a href="#">Enviar link</a></p></div>
                <?php } ?>

    </div>

This is correct in place:

<div id="news">
        <?php foreach ($articles as $article) { ?>
        <div><h2><?php echo $article['article_title']; ?></h2><br><span id="date">Publicado 
                <?php
                    setlocale(LC_ALL, 'pt_BR.utf8', 'Portuguese_Brazil');
                    //setlocale(LC_ALL, NULL);
                    date_default_timezone_set('Europe/Lisbon');

                    $uppercaseMonth = ucfirst(gmstrftime('%B'));
                    echo utf8_encode(strftime( '%a, '.$uppercaseMonth.' %d de %Y'/* - %H:%M'*/, $article['article_timestamp']));
                ?></span><p><?php echo $article['article_content']; ?><br><br><span id="print"><a onclick="javascript:window.print();" href="#">Imprimir</a></span><span id="link"><a href="#">Enviar link</a></p></div>
                <?php } ?>

    </div>
    
asked by anonymous 17.03.2014 / 12:00

1 answer

4

From the little I know about it, I think it has to do with the PHP version of the server that has online and localhost, and is explained here , in which if you have PHP with version lower than 5.4 the default characters are ISO-8859-1, between 5.4 and 5.6 are UTF-8 and only in the higher versions to 5.6 is that PHP uses the values given in setlocale() or default_charset of php.ini .

A possible solution to should indicate which encoding argument in

htmlentities(strftime( '%a, '.$uppercaseMonth.' %d de %Y'/* - %H:%M'*/, $article['article_timestamp']), "UTF-8");



(1) The term "default" means "by default", "pre-defined".     

17.03.2014 / 13:33