php中的字符格式

发布于 2024-08-05 17:58:28 字数 360 浏览 2 评论 0原文

抱歉,我无法登录,声明 ID 有服务器问题(我通常是 Arthur Gibbs),

当出现奇怪的字符时,我的数据库中的数据当前会输出此信息...
这只是一个例子

我得到的:De√ilscrat™
我想要的是: De√ilscrat™

似乎有些字符正在被其他人的系统翻译成字符代码。

所以我想知道的是:

是否有一个函数可以扩展字符代码在字符串内?
转动FUNCTION(De√ilscrat™)>>>>> De√ilscrat™

Sorry I can’t log in claim ID is having server issues (im normally Arthur Gibbs)

Data from my database currently outputs this when there are strange charecters...

This is just a example

What I get: De√ilscrat™
What I want: De√ilscrat™

It seems that some characters are being translated into character code by the other guys system..

So what I want to know is:

Is there a function that will expand charecter codes within a string?

Turning FUNCTION(De√ilscrat™) >>> De√ilscrat™.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怂人 2024-08-12 17:58:28

这个 东西看起来像一个 HTML 实体;所以,让我们尝试对其进行去实体化...

这可以使用 html_entity_decode 函数,由 PHP 提供。

例如,使用您提供的字符串,这里是一个代码示例:

// So the browser interprets the correct charsert
header('Content-type: text/html; charset=UTF-8');

$input = 'De√ilscrat™';
$output = html_entity_decode($input, ENT_NOQUOTES, 'UTF-8');

var_dump($input, $output);

我得到的输出是这个:

string 'De√ilscrat™' (length=19)
string 'De√ilscrat™' (length=15)

(第一个是原始版本,第二个是“解码”版本)

所以,这似乎可以解决问题;-)

This stuff looks like an HTML entity ; so, let's try de-entitying it...

This can be done using the html_entity_decode function, that's provided by PHP.

For instance, with the string you provided, here's a sample of code :

// So the browser interprets the correct charsert
header('Content-type: text/html; charset=UTF-8');

$input = 'De√ilscrat™';
$output = html_entity_decode($input, ENT_NOQUOTES, 'UTF-8');

var_dump($input, $output);

And the output I'm getting is this one :

string 'De√ilscrat™' (length=19)
string 'De√ilscrat™' (length=15)

(First one is the original version, and second one is the "decoded" version)

So, it seems to do the trick ;-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文