title: codeigniter auto_link doesnt add links without www
body: <p>If i type</p>
  
  <p><code>www.google.com</code> or <code>http://www.google.com</code></p>
  
  <p>using <code>auto_link()</code> function will add link correctly..</p>
  
  <p>However, if i type</p>
  
  <pre><code>google.com
  </code></pre>
  
  <p>the function doesnt work since the www. part is missing...</p>
  
  <p>how can i make sure it will include these links as well??</p>
  
  <p>This is the function from codeigniter:</p>
  
  <pre><code>/**
   * Auto-linker
   *
   * Automatically links URL and Email addresses.
   * Note: There's a bit of extra code here to deal with
   * URLs or emails that end in a period.  We'll strip these
   * off and add them after the link.
   *
   * @access  public
   * @param   string  the string
   * @param   string  the type: email, url, or both
   * @param   bool    whether to create pop-up links
   * @return  string
   */
  if ( ! function_exists('auto_link'))
  {
      function auto_link($str, $type = 'both', $popup = FALSE)
      {
          if ($type != 'email')
          {
              if (preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\&lt;]+)#i", $str, $matches))
              {
                  $pop = ($popup == TRUE) ? " target=\"_blank\" " : "";
  
                  for ($i = 0; $i &lt; count($matches['0']); $i++)
                  {
                      $period = '';
                      if (preg_match("|\.$|", $matches['6'][$i]))
                      {
                          $period = '.';
                          $matches['6'][$i] = substr($matches['6'][$i], 0, -1);
                      }
  
                      $str = str_replace($matches['0'][$i],
                                          $matches['1'][$i].'&lt;a href="http'.
                                          $matches['4'][$i].'://'.
                                          $matches['5'][$i].
                                          $matches['6'][$i].'"'.$pop.'&gt;http'.
                                          $matches['4'][$i].'://'.
                                          $matches['5'][$i].
                                          $matches['6'][$i].'&lt;/a&gt;'.
                                          $period, $str);
                  }
              }
          }
  
          if ($type != 'url')
          {
              if (preg_match_all("/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches))
              {
                  for ($i = 0; $i &lt; count($matches['0']); $i++)
                  {
                      $period = '';
                      if (preg_match("|\.$|", $matches['3'][$i]))
                      {
                          $period = '.';
                          $matches['3'][$i] = substr($matches['3'][$i], 0, -1);
                      }
  
                      $str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str);
                  }
              }
          }
  
          return $str;
      }
  }
  </code></pre>
  
  <p><strong>SOLUTION :</strong>
      function auto_link($str, $type = 'both', $popup = FALSE)
      {
          if ($type != 'email')
          {
                  if (!preg_match_all("/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/", $str, $matches)){</p>
  
  <pre><code>        if (preg_match_all("/(?:https?\:?(?:\/\/)?|www\.)?([a-zA-Z0-9\-\.]+\.(?:.[a-z]*))/mi", $str, $matches))
          {
              $pop = ($popup == TRUE) ? " target=\"_blank\" " : "";
  
              for ($i = 0; $i &lt; count($matches['0']); $i++)
              {
  
                              $str = str_replace($matches[0][$i],
                                                  '&lt;a href="http://'.$matches[1][0].'" class="auto_link_color"&gt;'.$matches[1][0].'&lt;/a&gt;', $str);
              }
          }
              }else{
                  for ($i = 0; $i &lt; count($matches['0']); $i++)
                  {
                      $str = str_replace($matches[0][$i], $matches[0][0], $str);
                  }
              }
      }
  
      return $str;
  }
  </code></pre>
  
  <p>This solved my problems so whatever link the user enters will find it and add a link... Even if the user enters an email it wont add links on the domain part but instead will show it as text.</p>