系统/库下的Cart.php有一个正则表达式模式定义,无法使用阿拉伯语作为名称值。这有效:
$data = array(
'id' => "221212",
'qty' => 1,
'price' => 21.2,
'name' => 'dasdasdas'
);
但由于名称中含有阿拉伯语,因此失败了:
$data = array(
'id' => "221212",
'qty' => 1,
'price' => 21.2,
'name' => 'عمر'
);
现在在Cart.php类中,我发现了以下内容:
// These are the regular expression rules that we use to validate the product ID and product name
var $product_id_rules = '\.a-z0-9_-';
// alpha-numeric, dashes, underscores, or periods
var $product_name_rules = '\.\:\-_a-z0-9';
// alphanumeric, dashes, underscores, colons or periods
我关注名称规则。显然这是问题,因为稍后会有一个检查:
if ( ! preg_match("/^[".$this->product_name_rules."]+$/i", $items['name'])) {
log_message('error', 'An invalid name was submitted as the product name: '.$items['name'].' The name can only contain alpha-numeric characters, dashes, underscores, colons, and spaces');
return FALSE;
}
如何替换名称规则字符串以使用阿拉伯语?我的正则表达式背景很差,所以请帮帮忙。
谢谢!
答案 0 :(得分:0)
如果您将$product_name_rules
(部分)模式更改为:
var $product_name_rules = '\.\:\-_a-z0-9\p{Arabic}';
...然后将/u
修饰符添加到preg_match
实际使用的模式中:
if ( ! preg_match("/^[".$this->product_name_rules."]+$/iu",
$items['name'])) { ... }
引用doc:
u(PCRE_UTF8)
此修饰符打开PCRE的其他功能 这与Perl不兼容。模式字符串被视为UTF-8。 在Unix上可以从PHP 4.1.0或更高版本获得此修饰符 从win32上的PHP 4.2.3开始。从PHP 4.3.5开始检查模式的UTF-8有效性。
答案 1 :(得分:0)
如果您想接受其他字符,则必须在加载购物车库后修改$ this-> cart-> product_name_rules。
$this->load->library('cart');
$this->cart->product_name_rules = '\.a-z0-9_-\p{Arabic}';
答案 2 :(得分:0)
将product_name
正则表达式更改为以下内容,允许全部:
var $product_name_rules = '^.'