Here's a function that was sent to me in response to me needing the exact 
same thing:

function pb_t2h_URLMarkup ($Text, $StyleClass = '', $Target = '')
{
         if ($StyleClass != '')
                 $ClassS = " class='$StyleClass'";
         else
                 $ClassS = "";

         if ($Target != '')
                 $TargetS = " target='$Target'";
         else
                 $TargetS = '';

         /* Match for URL strings (the part after 'http://'). Only does quite
          * loose matching. Handles URL parameters and urlencoded chars (%xy).
          * '&' chars have to be treated specially because htmlentities()
          * converts them to '&' */
         $URLSMatch = '([\w\.\/~\?%=\-\&]|&)+)';

         $Patterns = array ('/([^"\']|\A)(http:\/\/' . $URLSMatch . '/',
                            '/([^"\'])(ftp:\/\/[\w\.\/~\-]+)/',
                            '/([^"\'\w-\.\/]|\A)(www\.' . $URLSMatch . '/',
                            '/([^"\'\w\.~\-=]+@[\w\.~\-]+)/');

         $Replacements = array ("\\1<a href='\\2'$ClassS$TargetS>\\2</a>",
                                "\\1<a href='\\2'$ClassS$TargetS>\\2</a>",
                                "\\1<a 
href='http://\\2'$ClassS$TargetS>\\2</a>",
                                "<a href='mailto:\\1'$ClassS>\\1</a>");

         return preg_replace ($Patterns, $Replacements, $Text);
}


At 10:35 AM 3/14/2002 -0600, Tyler Longren wrote:
>Hello,
>
>I've been playing with this since lastnight.  I have a string of
>text...Example:
>"This is a test string of test, please go to http://www.google.com now."
>
>I need something that will catch the "http://www.google.com"; part, and make
>into a link instead of just plain text.  Does anyone know how I should go
>about doing this?  I've looked through a few code repositories, but haven't
>found anything.
>
>Thanks,
>Tyler
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to