通过PHP将♥插入MySQL(心脏字符)

Ale*_*x C 5 php mysql encoding utf-8

我有一点时间使用php将♥类型字符放入我的数据库.

我在页面上设置了UTF-8

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Run Code Online (Sandbox Code Playgroud)

和

<?php
$line = $_REQUEST['line'];
$line = stripslashes($line);
$line = htmlspecialchars($line);
$line = trim($line);
$line = mysql_real_escape_string($line);
mysql_query("SET CHARACTER SET utf8");

$sql = "INSERT INTO posts (txt) values ('$line')";
mysql_query($sql, $cn);

?>
Run Code Online (Sandbox Code Playgroud)

插入的结果是?字符

我确信有人做过这个,但我真的很难做到这一点.

编辑:

MySQL表的排序规则和字段的编码也设置为utf8_unicode_ci

med*_*iev 3

我相信你必须这样做:SET NAMES utf8作为你的第一个查询。