title: Create and simplify links from body of text in PHP
body: <p>I need to extract all links in a body of text in php and make them clickable. The problem is I can't seem to simplify the text of the link in any way.</p>
  
  <p>I tried using preg_replace_callback but I can't seem to get the trimming function working properly:</p>
  
  <pre><code>function trimUrl($url){
      $maxLength = 3;
      if(strlen($url)&gt;$maxLength){ 
          $urlShort = substr($str,0,$maxLength).'...'; 
      }
      else{ 
          $urlShort = $url; 
      }
      return $urlShort;
  }
  
  function enableLinks($text){
      return preg_replace_callback("!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&amp;;//=]+)!i", "&lt;a href='$1' target='_blank'&gt;".trimUrl("$1")."&lt;/a&gt;", $text);
  }
  
  enableLinks("Visit more work at http://www.google.com");
  </code></pre>
  
  <p>How can I run a second function within the preg_replace_callback that trims the output text?</p>