[英]Replace all characters except letters, numbers and spaces
I have a problem when i use preg_replace
. 使用
preg_replace
时出现问题。 I have this code : 我有这个代码:
$title = 'this $@*$@)(*$)(@*) 89898 is ' an "" exemple !!!:';
$titlefinal = preg_replace('/[^ \w]+/', '', $title);
This echo's : this 89898 is 039 an quotquot exemple
这是:
this 89898 is 039 an quotquot exemple
This code shown only the letters and numbers but it shows the '039' for the '
and 'quotquot' for the ""
, how can i make my code so only numbers, letters and space whould show up nothing else. 该代码仅显示字母和数字,但对“”显示“ 039”,对
'
“ quotquot ""
,我如何制作代码,因此仅数字,字母和空格不会显示其他内容。
Found it! 找到了! After another research on stackoverflow i figured this code:
在对stackoverflow的另一项研究之后,我发现了以下代码:
$titlefinal = preg_replace('/[^a-zA-Z0-9\s]/', '', html_entity_decode($title, ENT_QUOTES));
$title = preg_replace('/[^\da-z ]/i', '', $title);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.