I have a string that's coming to me formatted like
我有一个格式化的字符串
Ciel Spa at SLSâ„¢ is a celestial dreamscape
I have a formatting script that changes it to
我有一个格式化脚本,将其更改为
Ciel Spa at SLS™ is a celestial dreamscape
The script changes the encoding
脚本会更改编码
return iconv("UTF-8", "ISO-8859-1//TRANSLIT//IGNORE", $str)
The above iconv() would normally return the trademark symbol as the normal characters TM. This won't work for me, so I have the symbol replaced with a string that I can catch later on.
上述iconv()通常会将商标符号作为普通字符TM返回。这对我来说不起作用,所以我将符号替换为后来可以捕获的字符串。
str_replace("(TM)","™",$str);
This works great when I'm viewing the source in the browser, but when I push this text to imagettftext() the trademark symbol is ignored, effectively making the string
当我在浏览器中查看源代码时,这非常有用,但是当我将此文本推送到imagettftext()时,商标符号将被忽略,从而有效地使字符串生效
Ciel Spa at SLS is a celestial dreamscape
but of course rendered as an image.
但当然呈现为图像。
I know that the trademark symbol is supported in the font I'm using, but I'm not sure why it's disappearing. mb_detect_encoding() returns null, whereas for most of my strings it returns UTF-8.
我知道我使用的字体支持商标符号,但我不确定它为什么会消失。 mb_detect_encoding()返回null,而对于我的大多数字符串,它返回UTF-8。
I'm ready for a gritty, dirty workaround as nothing so far has worked. I tried using combinations of html_entity_decode() and str_replace() to no avail. An earlier version of the same formatting script combined a long array of UTF junk character replacements, without changing the encoding of the string, then fed it to imagettftext() and it appeared fine. I can't seem to get that back...any ideas??
因为到目前为止没有任何工作,我已经准备好了一个坚韧不拔的肮脏的解决方法。我尝试使用html_entity_decode()和str_replace()的组合无济于事。同一格式化脚本的早期版本组合了一长串UTF垃圾字符替换,而不更改字符串的编码,然后将其提供给imagettftext(),它看起来很好。我似乎无法回复......任何想法?
1 个解决方案
#1
0
There is simply no trademark symbol included in the iso-8859-1 character encoding. The reason you are coming up with nothing displayed there is because you are replacing part of a valid iso-8859-1 string with a symbol that is outside the range for this character set.
iso-8859-1字符编码中根本没有包含商标符号。您之间没有显示任何内容的原因是因为您要使用超出此字符集范围的符号替换有效iso-8859-1字符串的一部分。
You might try your utf-8 to iso-8859-1 encoding change using
您可以尝试使用utf-8到iso-8859-1编码更改
function decode_characters($info)
{
$info = mb_convert_encoding($info, "HTML-ENTITIES", "UTF-8");
$info = preg_replace('~^(&([a-zA-Z0-9]);)~',htmlentities('${1}'),$info);
return($info);
}
This code comes from some quick research on the php man pages.
这段代码来自对php手册页的一些快速研究。
#1
0
There is simply no trademark symbol included in the iso-8859-1 character encoding. The reason you are coming up with nothing displayed there is because you are replacing part of a valid iso-8859-1 string with a symbol that is outside the range for this character set.
iso-8859-1字符编码中根本没有包含商标符号。您之间没有显示任何内容的原因是因为您要使用超出此字符集范围的符号替换有效iso-8859-1字符串的一部分。
You might try your utf-8 to iso-8859-1 encoding change using
您可以尝试使用utf-8到iso-8859-1编码更改
function decode_characters($info)
{
$info = mb_convert_encoding($info, "HTML-ENTITIES", "UTF-8");
$info = preg_replace('~^(&([a-zA-Z0-9]);)~',htmlentities('${1}'),$info);
return($info);
}
This code comes from some quick research on the php man pages.
这段代码来自对php手册页的一些快速研究。