Show quotes coming from Mysql

Asked

Viewed 28 times

0

In Mysql I have a table with the following data:

“Cavalo dado não se olha os dentes”, disse a professora
<br>
Segunda linha

I’m taking this field like this:

$sql = $pdo->prepare('SELECT texto FROM noticia');
$sql->execute();
$resultadoSql = $sql->fetchAll();
foreach($resultadoSql as $valorSql){
    $texto = nl2br($valorSql['texto']);
}

But it’s returning to me:

inserir a descrição da imagem aqui

Why do these squares enter? How to show quotes?

  • Dear Caio, this face that this are not quotes, at least not quotes from ASCII, can be a UNICODE, can be coding error page, may have been problem in INSERT (I believe the most likely);

  • @Guilhermenascimento thanks for the help. These data came from a database in Wordpress, I’m accessing the post table of Wordpress. Really if I edit the content and recollect the Apas, it appears. What can it be? And how to solve?

  • It seems to me likely to be some conversion of the ASCII quotes into some Brazilian, maybe the WP itself is converting at the time of saving, turning into (U+201C) when quotation marks " go left and (U+201D)... Note that although similar to the ASCII table they are not the same Codepoint. Your PHP page must be in iso-8859-1 or windows-1252 (both assumed by apache or browser), or if your PHP is even in UTF-8 then it means that these characters are not traditional quotes, but quotes created by the WP class itself to use codepoints and emojis themselves.

  • It’s really these quotes. It’s all in UTF-8. But do you see any around it? Because I need to list over 7000 texts, and many are like this...

1 answer

1


As I have already commented, it seems likely to be some conversion of ASCII quotes into some Brazilian, maybe Wordpress itself is converting at the time of saving, turning into (U+201C) when quotation marks (") go left and (U+201D) when they are to the right of some text

Note that although similar to the ASCII table they are not the same Codepoint. Your PHP page must be in iso-8859-1 or windows-1252 (both assumed by apache or browser), or if your PHP is even in UTF-8 then it means that these characters are not traditional quotes, but quotes created by the WP class itself to use their own codepoints and emojis.

I won’t claim that this is the best solution, but as it is working with another bank and not with the Wordpress API directly (maybe it itself provides something that "decodes" what they themselves have done) the iconv (needs to be libiconv, most PHP servers have - are "compiled" with this):

<?php

$exemplo = '“Cavalo dado não se olha os dentes”, disse a professora
Segunda linha';

$exemplo  = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $exemplo);

$texto = nl2br($exemplo);

echo $texto;

another interim solution would be str_replace (you’ll probably have to use utf8_decode), thus:

<?php

$exemplo = '“Cavalo dado não se olha os dentes”, disse a professora
Segunda linha';

$exemplo  = str_replace(array('“', '”'), '"', $exemplo);

$texto = nl2br($exemplo);

echo $texto;

Remember that the PHP document that uses this will have to be saved in "Utf-8 without BOM".

You can also start using header('Content-Type: text/html; charset=utf-8'), but that really only if you wish and of course the quotation marks there will still be the Unicodes (U+201C) and (U+201D)

  • Thanks, putting to replace " does not work. But I ended up finding that the quotes values are e (< 0x94 >e < 0x93 >). Helped me a lot, thanks!

  • @caiocafardo the iconv worked? I copied from the string you pasted in your question, in the test I did it worked: https://ideone.com/yO1Wsh, it is worth noting that all this I assumed you were using ISO88591 or windows1252 with codec on your page.

Browser other questions tagged

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