gpt4 book ai didi

php - 如何替换 PHP 字符串中的表意空间?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:43:59 26 4
gpt4 key购买 nike

表意空间是http://www.charbase.com/3000-unicode-ideographic-space , 是中日韩标点符号。它看起来像一个普通的空间,但它实际上在屏幕上占据了 2 个位置而不是 1 个(就像汉字那样)

我试过用str_replace("","",$mystring) 去掉它们,当然不行,因为我这里输入的空格是ASCII空格。我也试过用汉字输入法手动输入表意空间,但看起来这样我也会去掉部分其他字符的代码,它返回乱码。

那么我怎样才能去掉这些空格呢?

最佳答案

通过从您链接到的信息页面复制符号,我能够很好地替换字符。您可能想为表意空间创建一个 CONST 别名,以帮助更清晰地制作和查找/替换编码。

// contains ideographic space between words
$start = 'before after';

// contains ideographic space in needle parameter
$test1 = str_replace(' ', '_', $start);

// contains ideographic space
define('ID_SPACE', ' ');
$test2 = str_replace(ID_SPACE, '&', $start);

// contains normal space in needle parameter
$test3 = str_replace(' ','_',$start);

// make sure we are using utf8 for this test
header('Content-Type: text/html; charset=utf-8');

echo $start.'<br/>';
echo $test1.'<br/>';
echo $test2.'<br/>';
echo $test3;

输出:

before after
before_after
before&after
before after

针对问题进行编辑

虽然您看不到它,但该字符显示在显示的框中,只需像选择任何其他文本一样单击并拖动以选择,然后您可以根据需要粘贴它。您也可以只复制我的答案中包含空格的代码。如果您看到类似   的内容,那么您需要将字符集设置为 utf-8

enter image description here

关于php - 如何替换 PHP 字符串中的表意空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34280232/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com