It is necessary to choose from all friends, those who have not been sent a single message. If you do a search for a substring in a message, then everything works, but on the contrary, to select all who this message was not sent will not be received. Below is the working code in which there is all the users to whom a message was sent with the text - "Text for an example". Here is the code:
<?php header('Content-Type: text/html; charset=utf-8'); /** * Example 2. * Get access token via OAuth and usage VK API. * @link http://vk.com/developers.php VK API */ error_reporting(E_ALL); require_once('src/VK/VK.php'); require_once('src/VK/VKException.php'); $vk_config = array( 'app_id' => '******', 'api_secret' => '***************', 'callback_url' => '', 'api_settings' => 'messages,friends', 'token' => '*************************************************' ); try { $vk = new VK\VK($vk_config['app_id'], $vk_config['api_secret'], $vk_config['token']); $access_token = $vk_config['token']."<br>"; echo 'access token: ' . $access_token; $user_friends = $vk->api('friends.get', array( 'uid' => '*********', 'fields' => 'uid,first_name,last_name', 'order' => 'name' )); $user_send_messeges = $vk->api('messages.get', array( 'out' => '1', 'count' => '200', 'time_offset' => '0', 'offset' => '200' )); foreach ($user_send_messeges['response'] as $k => $v) { if (preg_match('!Текст для примера!si',$v['body'])) { foreach ($user_friends['response'] as $key => $value) { if ($value['uid'] == $v['uid']) { echo "<hr>"; echo $value['uid']." - ". $value['first_name']." ".$value['last_name'].": ".$v['body']; } } } } } catch (VK\VKException $error) { echo $error->getMessage(); }