Insert a ♥ into MySQL (heart character) via PHP

I'm having a heck of a time getting ♥ type characters into my database using php.

I've got UTF-8 setting on the page

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

and

<?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);

?>

the result of the insert is a ? character

i'm sure there are people who've done this, but I'm really having trouble getting it right.

edit:

the MySQL table's collation and field's encoding is also set to utf8_unicode_ci


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

链接地址: http://www.djcxy.com/p/25178.html

上一篇: 从整理现代

下一篇: 通过PHP将♥插入MySQL(心脏字符)