PHP 中的 html_entity_decode 问题?
我正在尝试将 HTML 实体从源字符串转换为其等效的文字字符。
例如:
<?php
$string = "Hello – World";
$converted = html_entity_decode($string);
?>
虽然这正确地转换了屏幕上的实体,但当我查看 HTML 代码时,它仍然显示显式实体。我需要更改它,以便它从字面上转换实体,因为我没有在 HTML 页面中使用该字符串。
关于我做错了什么有什么想法吗?
仅供参考,我将转换后的字符串发送到 Apple 的推送通知服务:
$payload['aps'] = array('alert' => $converted, 'badge' => 1, 'sound' => 'default');
$payload = json_encode($payload);
I am trying to convert HTML entities from a source string to their literal character equivalent.
For example:
<?php
$string = "Hello – World";
$converted = html_entity_decode($string);
?>
Whilst this rightly converts the entity on screen, when I look at the HTML code it is still showing the explicit entity. I need to change that so that it literally converts the entity as I am not using the string within an HTML page.
Any ideas on what I am doing wrong?
FYI I am sending the converted string to Apple's Push notification service:
$payload['aps'] = array('alert' => $converted, 'badge' => 1, 'sound' => 'default');
$payload = json_encode($payload);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
–
映射到 UTF-8 字符(长破折号),因此您需要指定 UTF-8 作为字符编码:–
maps to a UTF-8 character (the em dash) so you need to specify UTF-8 as the character encoding:尝试使用字符集
这应该可以
并且它也应该在源中转换
Try using charset
This should work
And it should be converted also in the source