使用preg_match检测字符串中的波斯(波斯)字符 [英] using preg_match to detect persian (farsi) characters in string

查看:111
本文介绍了使用preg_match检测字符串中的波斯(波斯)字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从服务器端验证表单数据. 我的兴趣是用户只需用波斯语字符填写表格即可.

I am trying to validate form data from server-side. my interest is that the user just fill the form by Persian characters.

我正在使用以下代码:

$name=trim($_POST['name']);
$name= mysql_real_escape_string($name);
if (preg_match('/^[\u0600-\u06FF]+$/',str_replace("\\\\","",$name))){$err.= "Please use Persian characters!";}

但是它不起作用!

这是警告:

Warning: preg_match() [function.preg-match]: Compilation failed: PCRE does not support \L, \l, \N, \U, or \u at offset 3 in C:\xampp\htdocs\site\form.php on line 38

我该怎么办?

推荐答案

此应"工作...

**在开头[后面添加了一个^,以排除匹配中的阿拉伯/波斯字符...

** added a ^ after the opening [ to exclude arabic/farsi characters from the match...

if (preg_match('/^[^\x{600}-\x{6FF}]+$/u', str_replace("\\\\","",$name)))

这篇关于使用preg_match检测字符串中的波斯(波斯)字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆