Codeigniter列出錯誤的郵件地址

來源:互聯網
上載者:User
大家好,我在用CodeIgniter PHP foreach 過一個email地址的表單,發現一些不符合Regex要求的Email,列出來以便改進。

難題在於難以將結果以object形式列出來。

代碼:

PHP:

    $this->db->where('status', 'subscribed');    $email_preliminary=$this->db->select('email')->get('user');     $email_raw = array();    foreach ($email_preliminary->result() as $row):        $email_to_test=$row->email;        if(filter_var($email_to_test, FILTER_VALIDATE_EMAIL)||preg_match('/\d*[1-9]\d*/', $email_to_test))        {            $email_raw[] = $email_to_test;        }        else{        }    endforeach;    $record_raw=array_unique($email_raw);    $data['record'] = json_decode (json_encode ($record_raw), FALSE);    $this->load->view('login&signup/signup_test_view', $data);}

HTML Signup_test_view裡,我有:

  result() as $row): ?>email; ?>

錯誤資訊為:

Call to a member function result() on a non-object in D:\views\login&signup\signup_test_view.php

但我不是已經用下面這行代碼把array轉變成object了嗎:

  $data['record'] = json_decode (json_encode ($record_raw), FALSE);

謝謝!

更新:

有同學建議把view裡的代碼改成

    email; ?>

也試了,錯誤資訊仍為:
A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: login&signup/signup_test_get_wrong_email_view.php

回複內容:

大家好,我在用CodeIgniter PHP foreach 過一個email地址的表單,發現一些不符合Regex要求的Email,列出來以便改進。

難題在於難以將結果以object形式列出來。

代碼:

PHP:

    $this->db->where('status', 'subscribed');    $email_preliminary=$this->db->select('email')->get('user');     $email_raw = array();    foreach ($email_preliminary->result() as $row):        $email_to_test=$row->email;        if(filter_var($email_to_test, FILTER_VALIDATE_EMAIL)||preg_match('/\d*[1-9]\d*/', $email_to_test))        {            $email_raw[] = $email_to_test;        }        else{        }    endforeach;    $record_raw=array_unique($email_raw);    $data['record'] = json_decode (json_encode ($record_raw), FALSE);    $this->load->view('login&signup/signup_test_view', $data);}

HTML Signup_test_view裡,我有:

  result() as $row): ?>email; ?>

錯誤資訊為:

Call to a member function result() on a non-object in D:\views\login&signup\signup_test_view.php

但我不是已經用下面這行代碼把array轉變成object了嗎:

  $data['record'] = json_decode (json_encode ($record_raw), FALSE);

謝謝!

更新:

有同學建議把view裡的代碼改成

    email; ?>

也試了,錯誤資訊仍為:
A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: login&signup/signup_test_get_wrong_email_view.php

array不也是蠻好用的麼,那你需要一個把array轉換成object ?

$obj = (object) $array;

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.