title: detect links from sql data and show only 50 letters of it as text
body: <p>I have been working on a coupon code website and was able to modify some settings, but this one seems to be troubling me...</p>
  
  <pre><code> &lt;?php $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
      $text = $item-&gt;description;               
      if(preg_match($reg_exUrl, $text, $url)) {
          $linktext = substr($url[0], 0, 50);
          $text1 = preg_replace($reg_exUrl, '&lt;a href="'.$url[0].'" rel="nofollow"&gt;&lt;b&gt;'.$linktext.'...&lt;/b&gt;&lt;/a&gt;', $text);
      } 
      else 
      {
          $text1= $text;
      }
      $modeddescription = $text ; //string retrieved from SQL ?&gt; 
  &lt;?php echo ( !empty( $item-&gt;description ) ? '&lt;span&gt;' . nl2br($text1) . '&lt;/span&gt;' : t( 'theme_no_description', 'No description.' ) ); ?&gt;
  </code></pre>
  
  <p>The above code outputs the coupons code's description from SQL and it was supposed to detect links from the SQL text data.
  What it does is it only detect the first link and if there is 10 links in that text, all the shows 10 links will be the same...
  for example, if the text is like</p>
  
  <pre><code>http://google.com and http://facebook.com are big companies.
  a good example for shopping site is http://amazon.com
  </code></pre>
  
  <p>it will output</p>
  
  <pre><code>http://google.com and http://google.com are big companies.
  a good example for shopping site is http://google.com
  </code></pre>
  
  <p>I hope someone out there will help me fix it.
  I am able to use another code and detect all links individually, but I really dont want to show the 500 character long link in the page. only want to display the first 50 letter of the lest as link title.</p>
  
  <p>this code is able to detect all individual links but how add line spacing and 50 character limit in it ?</p>
  
  <pre><code>$string = preg_replace( "~[[:alpha:]]+://[^&lt;&gt;[:space:]]+[[:alnum:]/]~","&lt;a href=\"\\0\"&gt;\\0&lt;/a&gt;", $text);
  echo ".$string.";?&gt;
  </code></pre>