且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从 PHP 字符串中删除除字母以外的所有内容

更新时间:2023-02-19 20:39:26

在 PHP 中,您可以使用(如@rczajka 和@mario 所建议的):

preg_replace('/PL/u', '', $str)

工作示例:http://codepad.viper-7.com/V78skl>

您可能想查看此正则表达式教程

How can I remove everything from a string apart from letters? I have an input field for first names.

In PHP, you can use (as suggested by @rczajka and @mario):

preg_replace('/PL/u', '', $str)

Working Example: http://codepad.viper-7.com/V78skl

You may want to checkout this Tutorial for regex