Doubt Php htmlentities

Asked

Viewed 181 times

1

This is just a desire to learn, I put into production a site that had been working for some time. and I noticed that utf8_encode worked on the localhost but does not work in production now. I implemented htmlentities and the result was reversed, in localhost the date is gone and in the net is perfect. Someone can explain to me why?

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

inserir a descrição da imagem aqui

so it looks bandstand on the net:

<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 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>

so it’s right on the spot:

<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>
  • put the code snippet so it’s better to give you a feedback

  • That’s it, just change the echo line to the date.Obgado

1 answer

4


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

A possible solution for should indicate which encoding argument in the

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



(1) The term "default" means "default", "default".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.