如何在php中使用或转换'÷'字符?

问题描述 投票:0回答:1

我有 5.6÷7.2 这样的值。

我搜索符号:

$has_range = preg_match('/[÷\-\/]/', $option, $matches);

然后,如果我尝试记录

$matches[0]
,我会得到
"�"

为什么?

php character-encoding
1个回答
0
投票

这肯定是一个编码问题,请尝试在您的 php 文件中定义 UTF-8,并用于日志记录

$matches[0]
也在这里:

mb_internal_encoding("UTF-8");
mb_http_output("UTF-8");
$option = "5.6÷7.2";
$has_range = preg_match('/[÷\-\/]/u', $option, $matches);
if ($has_range) {
    error_log(var_export($matches[0], true));
}
© www.soinside.com 2019 - 2024. All rights reserved.