PHP中如何指定特殊字符

发布于 2024-07-26 08:26:34 字数 146 浏览 8 评论 0原文

我正在尝试在 FusionChart 图中的标签中输出西格玛字符 (σ)。 如何在 PHP 字符串中指定该字符? 我尝试过 htmlentity σ,但图表无法正确解释它。 有没有办法使用某种字符代码来指定 PHP 中的字符?

I am trying to output a sigma character (σ) in a label in a FusionChart graph. How can I specify that character in a PHP string? I have tried the htmlentity σ, but it is not interpreted correctly by the graph. Is there any way to specify the character in PHP using some sort of character code?

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

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

发布评论

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

评论(7

白龙吟 2024-08-02 08:26:34

您需要确保在输出时发送正确的标头。

<?php

header('Content-Type: text/html; charset=utf-8'); 

$char = utf8_encode(html_entity_decode('σ'));

echo $char;

这将输出字符。

编辑

如果将字符传递到图形中不起作用,则该软件不支持 UTF-8。

You need to make sure you're sending the correct headers when outputting.

<?php

header('Content-Type: text/html; charset=utf-8'); 

$char = utf8_encode(html_entity_decode('σ'));

echo $char;

This will output the character.

Edit:

If passing the character into the graph doesn't work, then the software doesn't support UTF-8.

心碎无痕… 2024-08-02 08:26:34

"\x1F" 适用于常规 ASCII 字符,但我认为 sigma 是 unicode 字符,因此您必须使用类似 utf8_encode。 PHP 对 Unicode 的支持很差。

"\x1F" will work for regular ASCII characters, but I think sigma is a unicode character, so you're going to have to use something like utf8_encode. PHP has poor Unicode support.

黑凤梨 2024-08-02 08:26:34

西格玛 (σ) 可以通过字节序列 xCF x83 (代码点 U+03C3)以 UTF-8 编码表示,因此您可以尝试构建 PHP 字符串

$sigma = "\xCF\x83";

但正如我不'不知道FusionChart,我不能说它是否可以处理UTF-8编码的字符串或多字节字符串。根据他们的产品描述,他们确实支持unicode(但需要UTF-8 BOM< /strong>),这样您就可以在 PHP 中构建 XML 响应:

$response = "\xEF\xBB\xEF<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<root>
    <element attribute=\"\xCF\x83\">\xCF\x83</element>
</root>";
header('Content-Type: text/xml; charset=utf-8'); 
echo $response;

ISO-8859-7 和 Windows-1253 中还有一个西格玛 (σ) 字符 (xF3) - 但我怀疑这会对您有帮助。

第三个选项是指定某种数学符号字体​​,将 sigma (σ) 映射到其他某个字符。

The sigma (σ) can be represented in UTF-8 encoding by the byte sequende xCF x83 (codepoint U+03C3), so you could try to build a PHP string

$sigma = "\xCF\x83";

But as I don't know FusionChart, I cannot say if it can handle UTF-8 encoded strings or multi-byte strings in general. According to their product description, they do support unicode (but require a UTF-8 BOM), so you can build the XML response in PHP:

$response = "\xEF\xBB\xEF<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<root>
    <element attribute=\"\xCF\x83\">\xCF\x83</element>
</root>";
header('Content-Type: text/xml; charset=utf-8'); 
echo $response;

There is also a sigma (σ) character in ISO-8859-7 and Windows-1253 (xF3) - but I doubt that this will help you.

Third option would be to specify some kind of mathematical symbol font that maps the sigma (σ) to some other character.

夜无邪 2024-08-02 08:26:34

我也可以使用 chr(229),其中 229 是我正在寻找的 ASCII 代码

I could use chr(229) as well, where 229 is the ASCII code I'm looking for

野却迷人 2024-08-02 08:26:34

对于 FusionCharts,要在图表中显示小西格玛,请使用 %CF%83。 将此百分比编码形式放入 php 字符串中。
我已经尝试过了。 有用。 另请在此处查看有关使用特殊字符的文档页面: http://www.fusioncharts.com /docs/Contents/SpChar_Eur​​o.html
http://www.fusioncharts.com/docs/Contents/SpChar_Pound.html
ETC。

For FusionCharts, to show small sigma in the chart, please use %CF%83. Put this percentage encoded form in a php string.
I have tried this. It works. Also check the documentation pages on using special characters here: http://www.fusioncharts.com/docs/Contents/SpChar_Euro.html
http://www.fusioncharts.com/docs/Contents/SpChar_Pound.html
etc.

伊面 2024-08-02 08:26:34

将您的 .php 文件保存为启用 bom 的 utf-8 编码,您可以直接使用西格玛字符 (σ)。

    $sXML = "<chart><set value='20' label='σ' /></chart>";
echo renderChartHTML("../FusionCharts/Column2D.swf", "", "$sXML", "myFirst", 600, 300, false);

Save your .php file as utf-8 encode with bom enabled,and you can use directly a sigma character (σ).

    $sXML = "<chart><set value='20' label='σ' /></chart>";
echo renderChartHTML("../FusionCharts/Column2D.swf", "", "$sXML", "myFirst", 600, 300, false);
永言不败 2024-08-02 08:26:34

怎么样:

html_entity_decode('σ');

html_entity_decode 的 PHP 手册

What about:

html_entity_decode('σ');

PHP Manual for html_entity_decode

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