php sprintf()是否带有外来字符? [英] php sprintf() with foreign characters?
问题描述
像sprintf一样的接缝对前移字符有问题吗?还是我做错了什么?从字符串中删除像åäö这样的字符时,它似乎可以正常工作.那有必要吗?
Seams to be like sprintf have a problem with foregin characters? Or is it me doing something wrong? Looks like it work when removing chars like åäö from the string though. Should that be necessary?
我希望为报告正确对齐以下几行:
I want the following lines to be aligned correctly for a report:
2011-11-27 A1823 -Ref. Leif - 12 873,00 18.98
2011-11-30 A1856 -Rättat xx - 6 594,00 19.18
我正在像这样使用sprintf():%-12s%-8s-%-10s-%20s%8.2f
I'm using sprintf() like this: %-12s %-8s -%-10s -%20s %8.2f
使用:php-5.3.23-nts-Win32-VC9-x86
Using: php-5.3.23-nts-Win32-VC9-x86
推荐答案
PHP中的字符串基本上是字节数组(不是字符).它们不能与多字节编码(例如UTF-8)一起在本地使用.
Strings in PHP are basically arrays of bytes (not characters). They cannot work natively with multibyte encodings (such as UTF-8).
有关详细信息,请参见:
https://www.php. net/manual/en/language.types.string.php#language.types.string.details
For details see:
https://www.php.net/manual/en/language.types.string.php#language.types.string.details
PHP中的大多数字符串函数都具有多字节等效项(带有mb_
前缀).但是sprintf
不会.
Most string functions in PHP have multibyte equivalent though (with the mb_
prefix). But the sprintf
does not.
在php.net上函数的文档页面上,有一个用户注释(由"textalk dot com的viktor"提供)具有sprintf
的多字节实现.它可能对您有用:
https://www.php.net/manual/en/function. sprintf.php#89020
There's a user comment (by "viktor at textalk dot com") with multibyte implementation of the sprintf
on the function's documentation page at php.net. It may work for you:
https://www.php.net/manual/en/function.sprintf.php#89020
这篇关于php sprintf()是否带有外来字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!