title: Regex: remove non-alphanumeric chars, multiple whitespaces and trim() all together
body: <p>I have a $text to strip off all non-alphanumeric chars, replace multiple white spaces and newline by single space and eliminate beginning and ending space.</p>
  
  <p>This is my solution so far. </p>
  
  <pre><code>$text = '
  some-    text!! 
  
  for testing?
  '; // $text to format
  
  //strip off all non-alphanumeric chars
  $text = preg_replace("/[^a-zA-Z0-9\s]/", "", $text);
  
  //Replace multiple white spaces by single space 
  $text = preg_replace('/\s+/', ' ', $text);
  
  //eliminate beginning and ending space
  $finalText = trim($text);
  /* result: $finalText ="some text for testing";
  without non-alphanumeric chars, newline, extra spaces and trim()med */
  </code></pre>
  
  <p>Is it possible to combine/achieve all these in one regular expression? as I would get the desired result in one line as below</p>
  
  <pre><code>$finalText = preg_replace(some_reg_expression, $replaceby, $text);
  </code></pre>
  
  <p>thanks</p>
  
  <p>Edit: clarified with a test string</p>