我目前對我的網站使用的是html和php,但在保存在textarea時遇到此問題。將特殊字符保存到數據庫中
每次我使用不同的字體,如「和」的特殊字符時,它就像◎(內含問號的黑色菱形)保存。通常發生在我複製其他網站的文本或複製文本時文檔然後將其粘貼,但是當我在textarea的類型,它工作正常
樣本:
多納特接受否定的答案,是誰關心
這裏是個人我的html代碼
<form action="savepost.php" method="POST">
<fieldset style="width:600px; height:580px">
<br><strong>Title</strong> <input id="posttitle" name="posttitle" type="text">
<br><br><strong>Content</strong>
<br><textarea id="postform" name="postform" style="width:600px; height:450px; resize: none"></textarea>
<br><input type="submit" value="Post" id="postbutton"/>
</fieldset>
</form>
Mysql的插入
$title = strtolower(mysql_real_escape_string($_POST['posttitle']));
$post_title = preg_replace('/[^a-zA-Z0-9\s]/','', $title);
$timestamp=time();
$post = $_POST['postform'];
$newtitle= preg_replace('/\\s+/', ' ',$post_title);
$striptitle = trim($newtitle, ' ');
$url = strtolower($timestamp.'/'.str_replace(" ", "-", $striptitle));
mysql_query("INSERT INTO blog (title, url, timestamp, post) VALUES ('$title', '$url', '$timestamp', '$post')");
什麼可以在這裏是什麼問題?
先生,我的代碼中已經有了代碼但是不起作用。它是否與MySQL中的數據類型有關? –
你沒有提到你正在放入數據庫 - 是的,檢查數據庫字符集以及列字符集 –
先生,我只是將排序規則設置爲utf8_unicode_ci,並使用 檢查它是否有效。 –