title: Use PHP to Convert Email Text to a Link
body: <p>Based on a question I had answered here ( <a href="https://stackoverflow.com/questions/14883967/use-php-to-replace-html-with-html">Use PHP to Replace HTML with HTML</a> ), I'd like to be able to filter my output text for email addresses, and convert those text emails to "mailto" links.</p>
  
  <p>Here's the PHP code that works, but only for converting some HTML to other HTML. What I've tried to do is have this function look for an email address, and convert it to a "mailto" link. For whatever reason, the code doesn't convert the email addresses. Here's my PHP:</p>
  
  <pre><code>function text_filter($string) {
      $search  = array('&lt;p&gt;__&lt;/p&gt;',   '/[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/');
      $replace = array('&lt;hr /&gt;',      '&lt;a href="mailto:$2"&gt;$2&lt;/a&gt;');
      $processed_string = str_replace($search, $replace, $string);
      echo $processed_string;
  }
  </code></pre>
  
  <p>When I use this function for output, this is what the code looks like:</p>
  
  <pre><code>&lt;?php text_filter( get_the_content() ); ?&gt;
  </code></pre>