Codeigniter列出错误的邮件地址

WBOY
Release: 2016-06-06 20:44:16
Original
1012 people have browsed it

大家好,我在用CodeIgniter PHP foreach 过一个email地址的表单,发现一些不符合正则表达式要求的Email,列出来以便改进。

难题在于难以将结果以object形式列出来。

代码:

PHP:

<code>    $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);
}
</code>
Copy after login
Copy after login

HTML Signup_test_view里,我有:

<code>  <?php foreach ($record->result() as $row): ?>

<span><?php echo $row->email; ?></span><br>

  <?php endforeach; ?>
</code>
Copy after login
Copy after login

错误信息为:

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

但我不是已经用下面这行代码把array转变成object了吗:

<code>  $data['record'] = json_decode (json_encode ($record_raw), FALSE);
</code>
Copy after login
Copy after login

谢谢!


更新:

有同学建议把view里的代码改成

<code>  <?php foreach ($record as $row): ?>
  <span><?php echo $row->email; ?></span><br>
   <?php endforeach; ?>
</code>
Copy after login
Copy after login

也试了,错误信息仍为:
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地址的表单,发现一些不符合正则表达式要求的Email,列出来以便改进。

难题在于难以将结果以object形式列出来。

代码:

PHP:

<code>    $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);
}
</code>
Copy after login
Copy after login

HTML Signup_test_view里,我有:

<code>  <?php foreach ($record->result() as $row): ?>

<span><?php echo $row->email; ?></span><br>

  <?php endforeach; ?>
</code>
Copy after login
Copy after login

错误信息为:

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

但我不是已经用下面这行代码把array转变成object了吗:

<code>  $data['record'] = json_decode (json_encode ($record_raw), FALSE);
</code>
Copy after login
Copy after login

谢谢!


更新:

有同学建议把view里的代码改成

<code>  <?php foreach ($record as $row): ?>
  <span><?php echo $row->email; ?></span><br>
   <?php endforeach; ?>
</code>
Copy after login
Copy after login

也试了,错误信息仍为:
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;

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template