我想在文本中搜索name,但出现此错误:


  警告:为foreach()提供了无效的参数


    $users = $db->query_read(" SELECT username FROM " . TABLE_PREFIX . " user ");
    $nameuser=array();
    while ($results = $db->fetch_array($users, MYSQLI_ASSOC))
    {
        $nameuser[] = $results['username'];
    }
    foreach ($nameuser as $name)
    {
        if(strstr($post['message'], $name))
        {
            // create new PM
            $pmdm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);
            $pmdm->set_info('is_automated', true);
            $pmdm->set('fromuserid', 1);
            $pmdm->set('fromusername', admin);
            $pmdm->set('title', 'some title');
            $pmdm->set('message', 'some text');
            $botpermissions['adminpermissions'] = 2;
            $pmdm->set_recipients($name, $botpermissions);
            $pmdm->set('dateline', TIMENOW);
            $pmdm->save();
        }
    }


编辑:
使用stripos代替strstr

最佳答案

你为什么:

$names = implode(',', $nameuser);
foreach ($names as $name)


只是:

foreach ($nameuser as $name)

10-04 20:49