Variable returns strange characters

Asked

Viewed 232 times

0

I am using the CPU-Z that when scanning your pc you have the option to save the log in txt or html so that it can be viewed manually. Done this I exported to html and ran

INSERT INTO `root`.`mycomputers`(id, token, html) VALUES (NULL, '08dade78-6f3c-401b-899f-aa7035d001fb', 'CODIGO_HTML_DO_LOG_DO_CPU-Z');

Where the id is A_I (Autoincrement)

I made the schema below so that the html is displayed every time I provide the correct token, but after the query the result returns an unknown character =

<?php
    $token = $_GET["token"];
    $html = "";
    $title = "";

    header ('Content-type: text/html; charset=UTF-8');

    mysql_connect("localhost", "root", "usbw");
    mysql_select_db("root");

    $cmd_q = "SELECT * FROM `mycomputer` WHERE token='$token'";
    $cmd_r = mysql_query($cmd_q);

    $cmd_s = mysql_fetch_row($cmd_r);
    $html = $cmd_s[2];
    $title = $cmd_s[3];
?>

<head>
    <link rel="shortcut icon" href="http://www.cpuid.com/medias/images/favicon.ico" type="image/x-icon"/>
    <script type="text/javascript">document.title="<?php echo $title; ?>"</script> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <meta charset="UTF-8" />
</head>
<?php echo $html; ?>

In certain characters such as the symbol next to the => ° C representing Degrees Celsius. The Html within the database returns instead of the ° that Temperature 0 32�C (89�F) [0x35] (Core #0)

NOTE: In the database the symbol ° is usually shown, but in html it is like this!

Other lines occurring the same:

     Temperature 0   38�C (100�F) [0x26] (TMPIN0)
        Temperature 1   35�C (95�F) [0x23] (TMPIN1)
        Temperature 2   32�C (89�F) [0x20] (TMPIN2)
        Fan 0   2742 RPM [0x223] (FANIN0)
        Fan 2   2836 RPM [0x211] (FANIN2)
        Fan PWM 0   63 pc [0xA0] (CPU)
        Fan PWM 1   60 pc [0x99] (System Fan 1)
        Fan PWM 2   60 pc [0x99] (System Fan 2)
        Fan PWM 3   60 pc [0x99] (System Fan 3)

Hardware monitor    NVIDIA NVAPI
        Temperature 0   45�C (113�F) [0x2D] (TMPIN0)

Jsfiddle

1 answer

1


If you have a problem with the character encoding pattern, try using it in your html head: change:

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

for:

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
  • It worked! But I still don’t understand, the difference between the two.

Browser other questions tagged

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