简体   繁体   English

除了PHP字符串中的字母以外的所

[英]Remove everything except letters from PHP string

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): 在PHP中,您可以使用(如@rczajka和@mario所建议的):

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

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

You may want to checkout this Tutorial for regex 您可能想要查看此教程以获取正则表达式

$new_string = preg_replace('/[^a-z]/i','',$old_string);
$new_string = ereg_replace("[^A-Za-z]", "", $string );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP从字符串中删除除数字以外的所有内容 - PHP Remove everything except numbers from string PHP删除除字母和连字符( - )之外的所有内容 - PHP remove everything except letters and a hyphen (-) 使用正则表达式从字符串中删除除图像标签以外的所有内容 - Remove everything except image tag from string using regular expression 从字符串中删除除具有特定模式的日期以外的所有内容 - Remove everything from a string except a date with a certain pattern 如何从字符串中删除除数字之外的所有内容并将它们放入数组中? - How to remove everything from a string except for the number and put these in an array? php-如何从字符串中切出所有内容,但在php中除了其中的某些部分? - How to cut out everything from a string except certain part of it in php? 从php中的字符串中删除俄语字母 - remove Russian letters from a string in php php-去除所有字符串,除了ASCII和表情符号 - php - strip a string of everything except ascii and emoji 使用preg_replace删除字符串中的所有内容,但数字,点和单个字母除外 - Remove everything from a string but numbers, dots and single letters with preg_replace 在 PHP 中删除从字符第一次出现到字符串末尾的所有内容 - Remove everything from the first occurrence of a character to the end of a string in PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM