0

Hello everyone I'm having problems with missing characters in my code, tried to use some things with utf-8 but didnt worked. the entire site is on php but the rest is working fine just this page that is having this problem.

<?php
      $tipo =$_GET["tipo"];

      $conexao = mysqli_connect("127.0.0.1","root","","db_tcc") or die ("Não foi possível se conectar com o servidor.");
      $varsql = "SELECT * FROM tb_guias WHERE TIPO=$tipo ORDER BY id ASC";
      $carregar_guias = mysqli_query($conexao, $varsql);




      while ($linha = mysqli_fetch_array($carregar_guias))
      {
        $titulo = $linha["TITULO"];
        $blob1 = $linha["IMG1"];
        $blob2 = $linha["IMG2"];
        $blob3 = $linha["IMG3"];
        $texto = $linha["TEXTO"];

        $img1 = imagecreatefromstring($blob1); 

        ob_start(); 
        imagejpeg($img1, null, 80);
        $data1 = ob_get_contents();
        ob_end_clean();

      $img2 = imagecreatefromstring($blob2); 

      ob_start(); 
      imagejpeg($img2, null, 80);
      $data2 = ob_get_contents();
      ob_end_clean();

      $img3 = imagecreatefromstring($blob3); 

      ob_start(); 
      imagejpeg($img3, null, 80);
      $data3 = ob_get_contents();
      ob_end_clean();


        echo "<div class='loc'><table class='tablel'><tr><td colspan='3'>$titulo</td></tr><tr><td>";
        echo '<img  src="data:image/jpg;base64,' .  base64_encode($data1)  . '" class="imag"  />';
       echo"</td><td>";
       echo '<img  src="data:image/jpg;base64,' .  base64_encode($data2)  . '" class="imag"  />';
       echo"</td><td>";
       echo '<img  src="data:image/jpg;base64,' .  base64_encode($data3)  . '" class="imag"  />';
       echo "</td></tr><tr><td colspan='3'>$texto</td></tr></table></div>";
        echo "<br><hr><br>";

      }
    ?>

1 Answers1

0

First you need to specify character set for HTML output.. in your page header add:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

in PHP you can use (this line must be first in your code):

<?php header("Content-type: text/html; charset=utf-8");?>

then you need to write a .htaccess in your root dir of your website:

`# Set httpd charset to utf-8 
 AddDefaultCharset On
 AddDefaultCharset utf-8`

Set php charset to utf-8 and setup mbstring (you may need to install mbstring module)

php_value default_charset utf-8
php_value mbstring.internal_encoding utf-8
php_value mbstring.func_overload 7

source

then try adding htmlentities function

your output would be like :

  echo '<img  src="data:image/jpg;base64,' .  htmlentities(utf8_encode($data1), 0, "UTF-8")  . '" class="imag"  />';
   echo"</td><td>";
   echo '<img  src="data:image/jpg;base64,' .  htmlentities(utf8_encode($data2), 0, "UTF-8")  . '" class="imag"  />';
   echo"</td><td>";
   echo '<img  src="data:image/jpg;base64,' .  htmlentities(utf8_encode($data3), 0, "UTF-8")  . '" class="imag"  />';
M0ns1f
  • 2,705
  • 3
  • 15
  • 25