简体   繁体   中英

Echo special characters from mysql

I am having Mysql database with column type of varchar(8192) latin2_croatian_ci . There i insert text like this: Čćžvasfamižsafaš (this is random text with special characters). When i preview data in mysql it does have that speical character (it wasn't replaced with ? or something else).

I have php page

<!DOCTYPE html>
<?php
    session_start();
    include("somePhpFile");

    $cid = $mysqli->escape_string($_GET["id"]);

    $sql = "SELECT BODY FROM ... WHERE CLANAKID = '$cid'";
    if($result = $mysqli->query($sql))
    {
        $clanak = mysqli_fetch_assoc($result);
        $body = $clanak["BODY"];
    }
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Some title</title>
    <link rel="stylesheet" type="text/css" href="../Styles/Clanak.css?id=4" />
    <link rel="stylesheet" type="text/css" href="../Styles/DefaultBody.css" />

    <meta charset="UTF-8"/> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1250"> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="../jQuery/Header.js"></script>
</head>

<body>
    <?php include("someHeaderphp");?>
    <div id="BodyDiv">
        <?php echo($body); ?>
    </div>
</body>

</html>

And when i echo it inside my page all special characters get replaced with ? and other characters. What could i do?

Here is my Show create table :

CREATE TABLE `CLANAK` (
 `CLANAKID` int(11) NOT NULL AUTO_INCREMENT,
 `NASLOV` varchar(64) NOT NULL,
 `BODY` varchar(8192) CHARACTER SET latin2 COLLATE latin2_croatian_ci NOT NULL,
 `THUMBNAIL` varchar(1024) NOT NULL,
 `AKTIVAN` int(11) NOT NULL DEFAULT '1',
 PRIMARY KEY (`CLANAKID`)
) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=latin1

First, let's do some debugging.

Please provide SHOW CREATE TABLE and

Let's see SELECT col, HEX(col) ... to dump what got into the table. For Čćžvasfamižsafaš , the HEX will be

3F3F3F76617366616D693F736166613F (???vasfami?safa?) - the text was messed up when storing.
C8E6BE76617366616D69BE73616661B9 - if it stored correctly into a latin2 column
C48CC487C5BE76617366616D69C5BE73616661C5A1 - correctly stored into utf8 (or utf8mb4)

Trouble with UTF-8 characters; what I see is not what I stored

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM