preg_replace 删除标点符号、空格和单词所有格形式?

发布于 2024-09-30 21:37:49 字数 430 浏览 3 评论 0原文

$text =
"<tab><return><nbsp>O'Neil  really  
likes his pudding's, he really really does!!!1.5"

如果可能的话,我希望有这个,其中 '' 是一个实际的制表符 \t 空间,而不是字面上的 '' >

$text = "O'Neil really likes his pudding he really really does 1.5"

删除白色步伐并用一个空格、标点符号替换它们,保留撇号后面的数字或任何不是 's' 的内容。

非常感谢!

$text =
"<tab><return><nbsp>O'Neil  really  
likes his pudding's, he really really does!!!1.5"

I would like to have this if possible where '<tab>' is an actual tab \t space not literally '<tab>'

$text = "O'Neil really likes his pudding he really really does 1.5"

removing the whites paces and replaces them with one space, the punctuation, keeping the numbers or anything after apostrophe thats not a 's'.

Thank you so much!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掀纱窥君容 2024-10-07 21:37:49
$string = trim(preg_replace(array('~[:;!?]|[.,](?![0-9])|\'s~', '~\s+~'), array('', ' '), $string));

首先去掉 ,然后用一个空格替换多个空格。最终它会删除前导和尾随空白。

$string = trim(preg_replace(array('~[:;!?]|[.,](?![0-9])|\'s~', '~\s+~'), array('', ' '), $string));

That first gets rid of 's and then replaces multiple whitespace with one space. Eventually it removes leading and trailing whitespace.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文