PHP和欧元符号

Fre*_*red 1 php unicode

让我们假设将以下字符串输入表单并提交给PHP脚本.

"€应编码为€"

我想知道如何实际将€编码为€ htmlentities()不会这样做,需要什么伏都教以便正确编码(以及其他喜欢它)?

Gum*_*mbo 5

它适用于htmlentities.但是你需要确保使用正确的字符集作为htmlentities'默认字符集ISO 8859-1不包含该字符; 但ISO 8859-15例如:

var_dump(htmlentities("\xA4", ENT_COMPAT, 'ISO-8859-15') === '€');  // bool(true)
Run Code Online (Sandbox Code Playgroud)

"\xA4"将导致字节0xA4,即ISO 8859-15中的代码.

因此,请确保使用包含该字符的字符集.