我必须警告你,它看起来毫无希望。
无论如何,您可以使用一系列正则表达式来做一些事情:
// This replaces , . ! ? (if NOT followed by a space) with the same (\1),
// followed by a space, followed by whatever followed it before (\2).
// Note that . and ? are special characters for regexes, so we have to
// escape them with a "\".
$bio = preg_replace('#([,\.!\?])(\S)#ms', '\1 \2', $bio);
// Then replace all extra spaces: any sequence of 2 or more spaces is
// replaced by one space.
$bio = preg_replace('# {2,}#ms', ' ', $bio);
// Then ., !, and ? followed by lowercase should uppercase it
// We take the full monty, ". m" and uppercase it all. Since the uppercase
// of ". " remains ". ", we keep things simpler.
$bio = preg_replace('#[\.!\?] [a-z])#ms', 'strtoupper("\1")', $bio);
// Then replace ALL CAPS words with lowerspace equivalent.
// Doesn't seem a really good idea though: "I am Mike, I worked with NASA"
// and NASA becomes nasa?
$bio = preg_replace('# ([A-Z][A-Z]+)#mse', 'strtolower(" \1")', $bio);
这样,你的句子就变成了:
这是迈克的简历,无缘无故地大写!问号和单词之间没有空格吗?问号也应该有一个空格。同样在停车标志之后应该有大写字母,逗号之间有空格,并且,这个,一个