当前位置:Gxlcms > PHP教程 > PHP正则匹配求解答

PHP正则匹配求解答

时间:2021-07-01 10:21:17 帮助过:2人阅读

这是网上找的一段全角符号转半角符号的函数,使用了下确实有效,使用的原理是中文标点的第二个字节减去0X80(即128)所得的数字就是半角所得的数字,但还是不符合我的需求,我希望的能够从一段文本中将全角符号转成半角符号而对文字不转换。

例如:

原文:如果我连身边最重要的人都保护不了的话,我当这个魔君还有什么意义。
转为:如果我连身边最重要的人都保护不了的话,我当这个魔君还有什么意义.

请问这个该如何匹配???

还是需要说将文本中的字符串转成数组,例遍数组遇到全角转成半角,再组成文本。

回复内容:

这是网上找的一段全角符号转半角符号的函数,使用了下确实有效,使用的原理是中文标点的第二个字节减去0X80(即128)所得的数字就是半角所得的数字,但还是不符合我的需求,我希望的能够从一段文本中将全角符号转成半角符号而对文字不转换。

例如:

原文:如果我连身边最重要的人都保护不了的话,我当这个魔君还有什么意义。
转为:如果我连身边最重要的人都保护不了的话,我当这个魔君还有什么意义.

请问这个该如何匹配???

还是需要说将文本中的字符串转成数组,例遍数组遇到全角转成半角,再组成文本。

你的方法不错,不过复杂了点,看我的

$arr1 = ["1","2","3","A","B","C","D","F","W","S","\",""",",",".","?","<",">","{","}","[","]","*","&","^","%","#","@","!","~","(",")","+","-","|",":",";","。"];
$arr2=["1","2","3","A","B","C","D","F","W","S","\\","\"",",",".","?","<",">","{","}","[","]","*","&","^","%","#","@","!","~","(",")","+","-","|",":",";","."];
$str="如果我连身边最重要的人都保护不了的话,我当这个魔君还有什么意义。";
echo $str."
"; for ($i=0;$i

运行结果

如果我连身边最重要的人都保护不了的话,我当这个魔君还有什么意义。
如果我连身边最重要的人都保护不了的话,我当这个魔君还有什么意义.

人气教程排行