PHP中的特殊字符和双引号问题 [英] Special characters and double quotes issue in PHP
问题描述
我的数据库列中有这种值,
I have this kind of value in my db column,
FürstováMila法官"Ut enim ad minim veniam"
我使用PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
处理我所有的特殊字符,
I use PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
to handle all my special characters,
class database_pdo
{
# database handler
protected $connection = null;
# make a connection
public function __construct($dsn,$username,$password)
{
try
{
$this->connection = new PDO($dsn, $username, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e)
{
# call the get_error function
$this->get_error($e);
}
}
...
...
...
}
当我尝试在输入字段中打印该值时,
And when I try to print that value in my input field,
<input name="title" type="text" value="<?php echo $page->title;?>"/>
在输入字段中,我只会得到FürstováMila法官.
I only get Judge-Fürstová Mila in my input field.
如果我使用htmlentities
来解决双引号问题,
If I use htmlentities
to fix the double quotes issue,
<input name="title" type="text" value="<?php echo htmlentities($page->title);?>"/>
我在输入字段中得到了
法官-FÃrstováMila用最小的威尼姆广告"
那么,如何立即解决此特殊字符和双引号问题?
So, how can I fix this special characters and double quotes issue at once?
推荐答案
尝试使用htmlspecialchars()而不是htmlentities().
Try using htmlspecialchars() instead of htmlentities().
这篇关于PHP中的特殊字符和双引号问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!