获取 PHP 中所有 UTF-8 空白字符的完整列表的最简单方法

发布于 2024-08-20 22:43:57 字数 174 浏览 3 评论 0原文

在 PHP 中,获取所有 Unicode 的完整列表(字符串数组)的最优雅方法是什么空白字符,用utf8编码?

我需要它来生成测试数据。

In PHP, what's the most elegant way to get the complete list (array of strings) of all the Unicode whitespace characters, encoded in utf8?

I need that to generate test data.

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

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

发布评论

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

评论(4

李不 2024-08-27 22:43:57

多年后,在 Google 上查找 unicode 空白字符时,这个问题仍然是最热门的结果。 devio 的答案很好,但不完整。截至撰写本文时(2017 年 10 月),维基百科在此处提供了空白字符列表:https://en.wikipedia。 org/wiki/Whitespace_character

该列表指定了 25 个代码点,而当前接受的答案列出了 18 个。包括其他 7 个代码点,该列表为:

U+0009  character tabulation
U+000A  line feed
U+000B  line tabulation
U+000C  form feed
U+000D  carriage return
U+0020  space
U+0085  next line
U+00A0  no-break space
U+1680  ogham space mark
U+180E  mongolian vowel separator
U+2000  en quad
U+2001  em quad
U+2002  en space
U+2003  em space
U+2004  three-per-em space
U+2005  four-per-em space
U+2006  six-per-em space
U+2007  figure space
U+2008  punctuation space
U+2009  thin space
U+200A  hair space
U+200B  zero width space
U+200C  zero width non-joiner
U+200D  zero width joiner
U+2028  line separator
U+2029  paragraph separator
U+202F  narrow no-break space
U+205F  medium mathematical space
U+2060  word joiner
U+3000  ideographic space
U+FEFF  zero width non-breaking space

Years later, this question still has top results on Google when looking for unicode whitespace characters. devio's answer is great, but incomplete. As of this writing (October 2017) Wikipedia has a list of whitespace characters here: https://en.wikipedia.org/wiki/Whitespace_character

This list has specifies 25 code points, whereas the currently accepted answer lists 18. Including the seven other code points, the list is:

U+0009  character tabulation
U+000A  line feed
U+000B  line tabulation
U+000C  form feed
U+000D  carriage return
U+0020  space
U+0085  next line
U+00A0  no-break space
U+1680  ogham space mark
U+180E  mongolian vowel separator
U+2000  en quad
U+2001  em quad
U+2002  en space
U+2003  em space
U+2004  three-per-em space
U+2005  four-per-em space
U+2006  six-per-em space
U+2007  figure space
U+2008  punctuation space
U+2009  thin space
U+200A  hair space
U+200B  zero width space
U+200C  zero width non-joiner
U+200D  zero width joiner
U+2028  line separator
U+2029  paragraph separator
U+202F  narrow no-break space
U+205F  medium mathematical space
U+2060  word joiner
U+3000  ideographic space
U+FEFF  zero width non-breaking space
夜深人未静 2024-08-27 22:43:57

此电子邮件(存档此处)包含以 UTF-8、UTF-16 和 HTML 编码的所有 Unicode 空白字符的列表。

在存档链接中查找“utf8_whitespace_table”函数。

static $whitespace = array(
    "SPACE" => "\x20",
    "NO-BREAK SPACE" => "\xc2\xa0",
    "OGHAM SPACE MARK" => "\xe1\x9a\x80",
    "EN QUAD" => "\xe2\x80\x80",
    "EM QUAD" => "\xe2\x80\x81",
    "EN SPACE" => "\xe2\x80\x82",
    "EM SPACE" => "\xe2\x80\x83",
    "THREE-PER-EM SPACE" => "\xe2\x80\x84",
    "FOUR-PER-EM SPACE" => "\xe2\x80\x85",
    "SIX-PER-EM SPACE" => "\xe2\x80\x86",
    "FIGURE SPACE" => "\xe2\x80\x87",
    "PUNCTUATION SPACE" => "\xe2\x80\x88",
    "THIN SPACE" => "\xe2\x80\x89",
    "HAIR SPACE" => "\xe2\x80\x8a",
    "ZERO WIDTH SPACE" => "\xe2\x80\x8b",
    "NARROW NO-BREAK SPACE" => "\xe2\x80\xaf",
    "MEDIUM MATHEMATICAL SPACE" => "\xe2\x81\x9f",
    "IDEOGRAPHIC SPACE" => "\xe3\x80\x80",
);

This email (archived here) contains a list of all Unicode whitespace characters encoded in UTF-8, UTF-16, and HTML.

In the archived link look for the 'utf8_whitespace_table' function.

static $whitespace = array(
    "SPACE" => "\x20",
    "NO-BREAK SPACE" => "\xc2\xa0",
    "OGHAM SPACE MARK" => "\xe1\x9a\x80",
    "EN QUAD" => "\xe2\x80\x80",
    "EM QUAD" => "\xe2\x80\x81",
    "EN SPACE" => "\xe2\x80\x82",
    "EM SPACE" => "\xe2\x80\x83",
    "THREE-PER-EM SPACE" => "\xe2\x80\x84",
    "FOUR-PER-EM SPACE" => "\xe2\x80\x85",
    "SIX-PER-EM SPACE" => "\xe2\x80\x86",
    "FIGURE SPACE" => "\xe2\x80\x87",
    "PUNCTUATION SPACE" => "\xe2\x80\x88",
    "THIN SPACE" => "\xe2\x80\x89",
    "HAIR SPACE" => "\xe2\x80\x8a",
    "ZERO WIDTH SPACE" => "\xe2\x80\x8b",
    "NARROW NO-BREAK SPACE" => "\xe2\x80\xaf",
    "MEDIUM MATHEMATICAL SPACE" => "\xe2\x81\x9f",
    "IDEOGRAPHIC SPACE" => "\xe3\x80\x80",
);
终难愈 2024-08-27 22:43:57

http://en.wikipedia.org/wiki/Space_%28punctuation%29#Spaces_in_Unicode不幸

的是,它不提供 UTF-8,但它确实在网页中提供了该字符,因此您可以剪切并粘贴到编辑器中(如果它以 UTF-8 保存)。或者, http://www.fileformat.info/info/unicode/char /180E/index.htm 给出 UTF-8(将“180E”替换为您正在查找的十六进制 UTF-16 值)。

这也提供了 @devio 的优秀答案所遗漏的一些额外字符。

http://en.wikipedia.org/wiki/Space_%28punctuation%29#Spaces_in_Unicode

Unfortunately, it doesn't give UTF-8, but it does have the character in the web page, so you could cut and paste into your editor (if it saves in UTF-8). Alternatively, http://www.fileformat.info/info/unicode/char/180E/index.htm gives UTF-8 (replace "180E" with the hex UTF-16 value you are looking up).

This also gives a couple extra characters that @devio's excellent answer misses.

嘿嘿嘿 2024-08-27 22:43:57
0x9 b'\t'
0xa b'\n'
0xb b'\x0b'
0xc b'\x0c'
0xd b'\r'
0x20 b' '
0x85 b'\xc2\x85'
0xa0 b'\xc2\xa0'
0x1680 b'\xe1\x9a\x80'
0x180e b'\xe1\xa0\x8e'
0x2000 b'\xe2\x80\x80'
0x2001 b'\xe2\x80\x81'
0x2002 b'\xe2\x80\x82'
0x2003 b'\xe2\x80\x83'
0x2004 b'\xe2\x80\x84'
0x2005 b'\xe2\x80\x85'
0x2006 b'\xe2\x80\x86'
0x2007 b'\xe2\x80\x87'
0x2008 b'\xe2\x80\x88'
0x2009 b'\xe2\x80\x89'
0x200a b'\xe2\x80\x8a'
0x200b b'\xe2\x80\x8b'
0x200c b'\xe2\x80\x8c'
0x200d b'\xe2\x80\x8d'
0x2028 b'\xe2\x80\xa8'
0x2029 b'\xe2\x80\xa9'
0x202f b'\xe2\x80\xaf'
0x205f b'\xe2\x81\x9f'
0x2060 b'\xe2\x81\xa0'
0x3000 b'\xe3\x80\x80'
0xfeff b'\xef\xbb\xbf'
0x9 b'\t'
0xa b'\n'
0xb b'\x0b'
0xc b'\x0c'
0xd b'\r'
0x20 b' '
0x85 b'\xc2\x85'
0xa0 b'\xc2\xa0'
0x1680 b'\xe1\x9a\x80'
0x180e b'\xe1\xa0\x8e'
0x2000 b'\xe2\x80\x80'
0x2001 b'\xe2\x80\x81'
0x2002 b'\xe2\x80\x82'
0x2003 b'\xe2\x80\x83'
0x2004 b'\xe2\x80\x84'
0x2005 b'\xe2\x80\x85'
0x2006 b'\xe2\x80\x86'
0x2007 b'\xe2\x80\x87'
0x2008 b'\xe2\x80\x88'
0x2009 b'\xe2\x80\x89'
0x200a b'\xe2\x80\x8a'
0x200b b'\xe2\x80\x8b'
0x200c b'\xe2\x80\x8c'
0x200d b'\xe2\x80\x8d'
0x2028 b'\xe2\x80\xa8'
0x2029 b'\xe2\x80\xa9'
0x202f b'\xe2\x80\xaf'
0x205f b'\xe2\x81\x9f'
0x2060 b'\xe2\x81\xa0'
0x3000 b'\xe3\x80\x80'
0xfeff b'\xef\xbb\xbf'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文