剥离所有内容,但PHP中的字母数字和欧洲字符除外 [英] Strip down everything, except alphanumeric and European characters in PHP
本文介绍了剥离所有内容,但PHP中的字母数字和欧洲字符除外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在验证我的注释脚本,我需要删除除西欧以外的所有非字母数字字符.
I am working on validating my commenting script, and I need to strip down all non-alphanumeric chars except those used in Western Europe.
我的计划是使用以下命令对所有非字母数字字符进行正则表达式:
My plan is to regex out all non-alphanumeric characters with:
preg_replace("/[^A-Za-z0-9 ]/", '', $string);
但是到目前为止,所有的欧洲字符和英镑符号都被去除了,因此CaféRouge"变成了"Caf Rouge".
But that so far strips out all European characters and a £ sign, so "Café Rouge" becomes "Caf Rouge".
如何向上述正则表达式添加欧元字符数组.
How can I add an array of Euro chars to the above regex.
该数组是:
£, €,
á, à, â, ä, æ, ã, å,
è, é, ê, ë,
î, ï, í, ì,
ô, ö, ò, ó, ø, õ,
û, ü, ù, ú,
ÿ,
ñ,
ß
我使用UTF-8
解决方案:
$comment = preg_replace('/[^\p{Latin}\d\s\p{P}]/u', '', $comment);
和
$name = preg_replace('/[^\p{Latin}]/u', '', $name);
$ name aslo删除标点符号和空格
$name aslo removes punctuation marks and spaces
感谢您的快速回复
推荐答案
preg_replace('/[^\p{Latin}\d ]/u', '', $str);
这篇关于剥离所有内容,但PHP中的字母数字和欧洲字符除外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文