简体   繁体   English

用正则表达式替换空格字符,PHP

[英]Replace space character with regular expression, php

I am using the function preg_replace('/[^0-9A-F]/', '', $string) to accept only numbers and letters but at the moment is not filtering spaces, how can I include that into my reg expression? 我正在使用函数preg_replace('/[^0-9A-F]/', '', $string)仅接受数字和字母,但目前不过滤空格,如何将其包含在reg表达式中? thanks 谢谢

preg_replace('/[^0-9A-F ]/', '', $string)

附带说明,您只允许使用A到F的大写字母。如果要所有字母:

 preg_replace('/[^0-9A-Z ]/i', '', $string)
preg_replace('/[^0-9A-F\x20]/', '', $string)

尝试

preg_replace('/[^0-9A-F]/',( )'', $string)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM