假设我们的XML包含类似
的节点<Name>ГАБИДУЛЛИН А З</Name>
如果我这样做
$lastname = $xpath->query(//Name/text()")->item(0)->textContent;
$sql = "call save_ticket_ordered($order_id, $ticket_num, '$lastname', '$time', '$user', @retcode);";
error_log("Calling stored procedure: " . $sql);
我在error.log中看到了
[Mon Oct 06 23:34:21.018149 2014] [:error] [pid 13255] [client 127.0.0.1:44050]调用存储过程:调用save_ticket_ordered(103696202,78290448213275,'\ xd0 \ x93 \ xd0 \ x90) \ xd0 \ x91 \ xd0 \ x98 \ xd0 \ x94 \ xd0 \ xa3 \ xd0 \ x9b \ xd0 \ x9b \ xd0 \ x98 \ xd0 \ x9d \ xd0 \ x90 \ xd0 \ x97','03 .10.2014 09:53' ,'xxxxxxx',@ verycode);
但如果我跑
$xmldoc = new DOMDocument();
$xmldoc->load("response.xml");
$xpath = new DOMXPath($xmldoc);
$lastname = $xpath->query("//Name/text()")->item(0)->textContent;
echo $lastname;
我能够在终端上看到正常的西里尔文结果,
ГАБИДУЛЛИНАЗ
那么你会建议我把目标放在DB中一个合适的西里尔字符串?
答案 0 :(得分:0)
假设您的数据库表和PHP文件是UTF-8编码的,在数据库连接之后,发送这些查询:
SET NAMES utf8
SET CHARSET utf8
例如,如果你正在使用PDO,你会做这样的事情:
$this->pdo = new \PDO($dsn, $user, $pass,
array(
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_EMULATE_PREPARES => false,
));
$this->pdo->exec('SET NAMES utf8');
$this->pdo->exec('SET CHARSET utf8');