title: How to select a word from a string containing a specific character or symbol in PHP?
body: <p>I want to get all the usernames from a post and send them notification.</p>
  
  <p>The post may look like this.</p>
  
  <pre><code>Congratulations 
  @user1 
  @user2 
  @user3 
  You have won!
  </code></pre>
  
  <p>I want to select all words from the above string that contains <code>@</code> symbol and store them as elements of an array so I can use them individually to send a notification to them.</p>
  
  <p>I am using the following code but it gives only on 1 user. How do I get the rest of them?</p>
  
  <pre><code>&lt;?php
  $post = "Congratulations 
  @user1
  @user2
  @user2
  You have won!";
  if (strpos($post, "@")) {
  $fetch = explode("@", $post);
  $show = explode("\r\n", $fetch[1]);
  $users = count($show);
  
  foreach ($show as $value) {
      echo "$value &lt;br&gt;";
  }
  echo "&lt;br&gt;Total $users users.";
  }
  ?&gt;
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I tried to get the users as suggested by @Pharaoh</p>
  
  <pre><code>&lt;?php
  $post = "Congratulations 
  @user1
  @user2
  @user2
  You have won!";
  if (strpos($post, "@")) {
  $matches = [];
  preg_match_all('/@(\w+)/', $post, $matches);
  $users = count($matches);
  $matches = array_values($matches);
  foreach ($matches as $value) {
      echo "$value &lt;br&gt;";
  }
  echo "&lt;br&gt;Total $users users.";
  }
  ?&gt;
  </code></pre>
  
  <p>It gives two arrays as output as below. </p>
  
  <pre><code>Array 
  Array 
  
  Total 2 users.
  </code></pre>
  
  <p>What am I doing wrong?</p>