检测标点符号并单独回显

时间:2012-06-12 12:32:31

标签: php punctuation

我想检测标点符号(!@#$%^& *()?<>“';:} {] [)在字符串中的任何位置(字符串前面或后面)...

$string = "'Hello!'";
$anotherstring = "Hi";

我希望它在$string中记录标点符号并用$anotherstring回显...

您好
'嗨!'

其实我正在制作一个拼写检查器,问题是它用标点符号检查字符串..我想在没有标点符号的情况下检查它并在建议之前回显标点之前和建议之后的标点后...

2 个答案:

答案 0 :(得分:0)

这可能是一个肮脏的伎俩:)

$anotherstring = preg_replace('/[a-zA-Z0-9]+/', $anotherstring, $string);

编辑:如果您不需要,可以删除数字

答案 1 :(得分:0)

查看http://us3.php.net/manual/en/function.strtok.php

您可以根据空格和符号等标记进行拆分。