title: Detect url that includes slashes in a string and replace it with link tag
body: <p>i am trying to detect url that includes slash (like: <a href="http://example.com/posts/30" rel="nofollow">http://example.com/posts/30</a>) in a string, and get it as a html tag like: </p>
  
  <pre><code>&lt;a href="http://example.com/posts/30"&gt;http://example.com/posts/30&lt;/a&gt;
  </code></pre>
  
  <p><strong>now, i have a function that doing this, but links with slashes not work, i get back an empty link name, other links works perfect (like: <a href="http://example.com/page.php?id=1" rel="nofollow">http://example.com/page.php?id=1</a>)</strong>, this is my functions:</p>
  
  <pre><code>//get links in string
  function makeLinks($str) {
      $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
      $urls = array();
      $urlsToReplace = array();
      if(preg_match_all($reg_exUrl, $str, $urls)) {
          $numOfMatches = count($urls[0]);
          $numOfUrlsToReplace = 0;
          for($i=0; $i&lt;$numOfMatches; $i++) {
              $alreadyAdded = false;
              $numOfUrlsToReplace = count($urlsToReplace);
              for($j=0; $j&lt;$numOfUrlsToReplace; $j++) {
                  if($urlsToReplace[$j] == $urls[0][$i]) {
                      $alreadyAdded = true;
                  }
              }
              if(!$alreadyAdded) {
                  array_push($urlsToReplace, $urls[0][$i]);
              }
          }
          $numOfUrlsToReplace = count($urlsToReplace);
          for($i=0; $i&lt;$numOfUrlsToReplace; $i++) {
              $str = str_replace($urlsToReplace[$i], "&lt;div class=\"dont-break-out\"&gt;&lt;a href=\"".$urlsToReplace[$i]."\" class=\"titled_url\" rel=\"nofollow\" target=\"_blank\"&gt;".get_title($urlsToReplace[$i])."&lt;/a&gt;&lt;/div&gt; ", $str);
          }
          return $str;
      } else {
          return $str;
      }
  }
  </code></pre>
  
  <p>and this is the function that gets the url title:</p>
  
  <pre><code>//get link title
  function get_title($url){
    $str = file_get_contents_utf8($url);
    if(strlen($str)&gt;0){
      $str = trim(preg_replace('/\s+/', ' ', $str)); // supports line breaks inside &lt;title&gt;
      preg_match("/\&lt;title\&gt;(.*)\&lt;\/title\&gt;/i",$str,$title); // ignore case
      $title_trimmed=trim($title[1]);
      if(!empty($title_trimmed)){
          return $title[1];
      }else{
  
      return $url;
  }
  </code></pre>
  
  <p>}
  }
  and this is the utf-8 file_get_contents:</p>
  
  <pre><code>function file_get_contents_utf8($fn) {
       $content = file_get_contents($fn);
        return mb_convert_encoding($content, 'UTF-8',
            mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));
  }
  </code></pre>
  
  <p>any help please ?</p>