是否需要更改表结构或更改哪个函数,所以请将解决方案放在这里。提前谢谢。
我的例子是:
$find_regex = 'Δ';
$replace_regex = 'Δ';
$sql = mysql_query("INSERT INTO regex_table (find_regex, replace_regex, import_date) VALUES ('$find_regex', '$replace_regex')");
当我运行上述代码时,它执行成功,但不是符号(find_regex),而是插入'?'
还有一件事,我已经尝试了所有的建议,如htmlentities, htmlspecialchar等在其他问题中提供的stackoverflow,但没有解决。
使用mysql_real_escape_string($data);//其中$data是包含特殊字符的字符串参考此处输入链接描述
在保存到数据库之前,你可以使用htmlentities()加密你的数据,当从数据库中检索数据时,你可以使用html_entity_decode()解密,看看下面的例子可能会对你有所帮助:
<?php error_reporting(E_ALL);
$servername = "localhost";
$username = "root";
$password = "";
$db = 'test_001';
// Create connection
$conn = new mysqli($servername, $username, $password, $db);
$find_regex = htmlentities('Δ');
$replace_regex = htmlentities('Δ');
$sql = "INSERT INTO regex_table (find_regex, replace_regex ) VALUES ("."'". mysqli_real_escape_string($conn, $find_regex)."', '". mysqli_real_escape_string($conn, $replace_regex)."')";
//exit;
$result = $conn->query($sql);
//For retrieving from database
$sql = "SELECT * FROM `regex_table`";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row['find_regex'].'<br>'.$row['replace_regex'].'<br>';
}
} else {
echo "0 results";
}
$conn->close();
?>