CodeIgniter购物车类阿拉伯语regex [英] CodeIgniter cart class Arabic regex
问题描述
系统/库下的Cart.php有一个正则表达式模式定义,不能使用阿拉伯语作为名称值。这个工作原理:
The Cart.php under system/library has a regex pattern definition that is not enabling me to use Arabic for name values. This works:
$data = array(
'id' => "221212",
'qty' => 1,
'price' => 21.2,
'name' => 'dasdasdas'
);
但是由于名称中有阿拉伯语,所以失败:
But this fails because of Arabic in the name:
$data = array(
'id' => "221212",
'qty' => 1,
'price' => 21.2,
'name' => 'عمر'
);
现在在Cart.php类中,我发现了以下内容:
Now in the Cart.php class, I found the following:
// 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
规则。显然这是问题,因为稍后有一个检查:
I am concerned with the name rules. Clearly this is the problem because later on there is a check:
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;
}
如何替换名称规则字符串以使用阿拉伯语?我有一个很差的背景与正则表达式,所以请帮助。
How can I replace the name rules string to work with Arabic? I have a very poor background with regex, so please help out.
谢谢!
>
推荐答案
将 product_name
regex更改为以下选项:
Change product_name
regex to the following, which allows all:
var $product_name_rules = '^.'
这篇关于CodeIgniter购物车类阿拉伯语regex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!