I want to allow the euro symbol € in this regex but it wont come through
我想在这个正则表达式中允许欧元符号€但它不会通过
$val = ereg_replace($regex, "[^a-zA-Z0-9[:space:][:blank:]€+-]+", $_REQUEST[$var]);
3 个解决方案
#1
1
In your comment, you've forgotten the delimiters required by preg_replace:
在您的评论中,您忘记了preg_replace所需的分隔符:
$string = 'ab!:;c+12,.3 €def-x/';
$string = preg_replace('/[^a-zA-Z0-9\s€+-]+/', '', $string);
echo $string,"\n";
output:
abc+123 €def-x
#2
5
Do you have mbstring instaled? If so, try using the function mb_ereg_replace(). It'll support this caracter (even in UTF-8).
你有没有mbstring instaled?如果是这样,请尝试使用函数mb_ereg_replace()。它会支持这个特征(即使在UTF-8中)。
Edit: Also check if mbregex is on. Some hosts turn mbstring on but disables mbregex (I don't know why).
编辑:还要检查mbregex是否打开。一些主机打开mbstring但禁用mbregex(我不知道为什么)。
#3
1
Check that the charset used by your text editor / IDE is iso-8859-15 (if this is why you are trying to display).
检查文本编辑器/ IDE使用的字符集是否为iso-8859-15(如果这是您尝试显示的原因)。
If it's UTF-8, you will have to do another replace especially for it (€
being represented on several bytes, I guess that it won't fit into a [...]
regex block).
如果它是UTF-8,你将不得不另外替换它(€表示在几个字节上,我猜它不适合[...]正则表达式块)。
BTW, ereg_replace()
has been deprecated in favor of preg_replace()
.
BTW,ereg_replace()已被弃用,转而使用preg_replace()。
Plus, why do you have two "regex" parameters? (I suppose that $regex
contains a regex too?)
另外,为什么你有两个“正则表达式”参数? (我想$ regex也包含一个正则表达式?)
Suggestion (untested), if what you want to do is remove € + other chars in your initial regex:
建议(未经测试),如果您想要做的是删除初始正则表达式中的€+其他字符:
$val = preg_replace(
array('/[^a-zA-Z0-9[:space:][:blank:]+\-]+/', '/€/'),
'',
$_REQUEST[$var]
);
#1
1
In your comment, you've forgotten the delimiters required by preg_replace:
在您的评论中,您忘记了preg_replace所需的分隔符:
$string = 'ab!:;c+12,.3 €def-x/';
$string = preg_replace('/[^a-zA-Z0-9\s€+-]+/', '', $string);
echo $string,"\n";
output:
abc+123 €def-x
#2
5
Do you have mbstring instaled? If so, try using the function mb_ereg_replace(). It'll support this caracter (even in UTF-8).
你有没有mbstring instaled?如果是这样,请尝试使用函数mb_ereg_replace()。它会支持这个特征(即使在UTF-8中)。
Edit: Also check if mbregex is on. Some hosts turn mbstring on but disables mbregex (I don't know why).
编辑:还要检查mbregex是否打开。一些主机打开mbstring但禁用mbregex(我不知道为什么)。
#3
1
Check that the charset used by your text editor / IDE is iso-8859-15 (if this is why you are trying to display).
检查文本编辑器/ IDE使用的字符集是否为iso-8859-15(如果这是您尝试显示的原因)。
If it's UTF-8, you will have to do another replace especially for it (€
being represented on several bytes, I guess that it won't fit into a [...]
regex block).
如果它是UTF-8,你将不得不另外替换它(€表示在几个字节上,我猜它不适合[...]正则表达式块)。
BTW, ereg_replace()
has been deprecated in favor of preg_replace()
.
BTW,ereg_replace()已被弃用,转而使用preg_replace()。
Plus, why do you have two "regex" parameters? (I suppose that $regex
contains a regex too?)
另外,为什么你有两个“正则表达式”参数? (我想$ regex也包含一个正则表达式?)
Suggestion (untested), if what you want to do is remove € + other chars in your initial regex:
建议(未经测试),如果您想要做的是删除初始正则表达式中的€+其他字符:
$val = preg_replace(
array('/[^a-zA-Z0-9[:space:][:blank:]+\-]+/', '/€/'),
'',
$_REQUEST[$var]
);