[英]extract regex from $this->request->data and store in DB cakephp
我在cakephp 2.0中使用FormHelper。 我想從輸入字段中提取21位數字,然后再保存到數據庫中,並且僅將其存儲在數據庫中。
我目前擁有的代碼是:
if (!empty ( $this->request->data ) && ($this->request->is('post')))
{
preg_match("/[0-9]{21}/", $this->request->data, $field_id);
$this->InsightId->save($field_id[0]);
}
if語句永遠不會被求值,也永遠不會進入preg_match。 我究竟做錯了什么?
我的解決方案與Regex完全不同。 我用php explode以'/'作為分隔符。 我的代碼現在看起來像這樣:
if (!empty ( $this->request->data ) && ($this->request->is('post')))
{
$field_ids = explode('/', $this->request->data['InsightId']['field']);
foreach($field_ids as $field_id)
{
if(strlen($field_id) === 21)
{
$this->request->data['InsightId']['field'] = $field_id;
$this->InsightId->save($this->request->data);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.