Text returning with "?" instead of quotes and hyphens

1

Good afternoon.

My site runs on ISO-8859-1 encoding and when I pull data from an external XML, some characters return as a question mark.

I tried to convert with <?php header("Content-type: text/html; charset=utf-8"); ?> but all the rest of the site like top, footer and other areas suffered with the coding change.

I've also added utf8_decode () and nothing solved.

Does anyone know of a solution to the problem?

A sample link link

<?php
                $arquivo = "https://api.dino.com.br/v2/news/$id/mundo-do-marketing";

                $info = file_get_contents($arquivo);

                $lendo = json_decode($info);

                echo '<pre>' . print_r($lendo, true) . '</pre>';

                echo $lendo->Item->Summary;

                $titulo = utf8_decode($lendo->Item->Title);
                $autor = utf8_decode($lendo->Item->Author);
                $retranca = utf8_decode($lendo->Item->Summary);
                $data = date('d/m/Y', strtotime($lendo->Item->PublishedDate));
                $categoria = utf8_decode($lendo->Item->Categories[0]->Name);
                $conteudo = utf8_decode($lendo->Item->Body);

                if($id == 108988){
                    redirect(base_url('noticias-corporativas'));
                }

                else{
            ?>

                    <h2><?php echo $titulo; ?></h2>
                    <p class="retranca-dino"><?php echo $retranca; ?></p>
                    <p class="autor-dino">Categoria: <span class="autor"><?php echo $categoria; ?></span></p>
                    <p class="autor-dino">Autor: <span class="autor"><?php echo $autor; ?></span></p>
                    <span class="data-dino">Data de Publicação: <span style="font-weight: normal;"><?php echo $data; ?></span></span>

                <?php
                        if(empty($lendo->Item->Image->Url)){
                            echo NULL;
                        }

                        else{

                            $imagem = $lendo->Item->Image->Url;
                ?>
                        <div class="imagem-dino">
                            <img class="imagem" src="<?php echo $imagem; ?>" alt="<?php echo $titulo; ?>" title="<?php echo $titulo; ?>" />
                        </div>

                <?php
                        }
                    }
                ?>

                <div class="conteudo-dino"><?php echo $conteudo; ?></div>

            <?php
                echo br(1);
            ?>

Att.

    
asked by anonymous 10.02.2017 / 19:33

2 answers

0

Following the PHP documentation you should use the utf8_encode function. Utf8_encode - Encodes an ISO-8859-1 string for UTF-8. See if it works.

    
10.02.2017 / 20:46
0

I've simulated your error here. What is probably happening is that even your site running in ISO, file_get_contents is already taking UTF-8 encoding.

The three alternatives to tidy up:

1.Take utf8_decode:

$conteudo = $lendo->Item->Body;

2.Completely the first (by taking the utf8_decode) by adding one:

ini_set( 'default_charset', 'utf-8');
  • Just add this line (keep the rest as it is in your code):

    ini_set ('default_charset', 'iso-8859-1');

  • 10.02.2017 / 22:33