Php 检测标点符号并单独回显

Php 检测标点符号并单独回显,php,punctuation,Php,Punctuation,我要检测标点!@$%^&*?';:}{][在字符串前面或后面的任何位置 $string = "'Hello!'"; $anotherstring = "Hi"; 我希望它将标点符号记录在$string中,并用另一个$string进行回显 $string = "'Hello!'"; $anotherstring = "Hi"; 你好 “嗨!” 实际上,我在做拼写检查,问题是它会检查带有标点符号的字符串。我想检查它而不带标点符号,并在建议前回显标点符号,在建议后回显标点符号…这可能是一个肮脏的把

我要检测标点!@$%^&*?';:}{][在字符串前面或后面的任何位置

$string = "'Hello!'";
$anotherstring = "Hi";
我希望它将标点符号记录在$string中,并用另一个$string进行回显

$string = "'Hello!'";
$anotherstring = "Hi";
你好 “嗨!”


实际上,我在做拼写检查,问题是它会检查带有标点符号的字符串。我想检查它而不带标点符号,并在建议前回显标点符号,在建议后回显标点符号…

这可能是一个肮脏的把戏:

$anotherstring = preg_replace('/[a-zA-Z0-9]+/', $anotherstring, $string);
编辑:如果不需要,可以删除这些数字


你可以根据诸如空格和符号之类的标记进行拆分。

拼写检查或语法检查?如果两边都有标点符号,它会起作用吗???@Mirko akkov但是如果我想回显建议前的标点符号和建议后的标点符号…@Mirko akkov你可以这样做:$cleanstring=preg\re放置“/[^a-zA-Z0-9]/”,$string;