title: How to count the special characters in a string using PHP
body: <p>I need to know how to find the number of occurrences of special characters in a string using PHP </p>
  
  <p>Here is the code...</p>
  
  <pre><code>&lt;?php
  
  $message=$_POST['Message'];
  //$rep=preg_replace("@ # $ % ^ &amp; / . * @"," ",$message);
  //$rep=preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&amp;-]/s', '', $message);
  $rep = preg_replace("/[^a-zA-Z]+/", "", $message);
  echo "There are ".str_word_count($message)." words found in the given message"."&lt;br/&gt;";
  
  $len=strlen($rep);
  echo "length of the message is ".$len;
  $delims="?#";
  $word = strtok($message, $delims);
  
  echo "delim ".$word."&lt;br/&gt;";
  echo $delimlen=strlen($word)."&lt;br/&gt;";
  
  echo "without special ".$rep;
  
  
  ?&gt;
  </code></pre>