[FX.php List] URLs in text

DC dan.cynosure at dbmscan.com
Wed Jan 3 11:22:32 MST 2007


The original regexp reads in English:

look for
one or more alphabetical characters
followed by
colon forwardslash forwardslash
followed by
one or more characters that are not
the lessthan char or the greaterthan char or
space (including tabs and other whitespace)
followed by
one alphanumeric or forwardslash
at the end

then take the whole thing and put it into a link

i suggest you modify regexp to allow only http or HTTP or https or HTTPS 
links:

$str = 
ereg_replace("[Hh][Tt][Tt][Pp][Ss]?://[^<>[:space:]]+[[:alnum:]/]","<a 
href=\"\\0\">\\0</a>", $str);

cheers,
dan

Steve Winter had written:
> Bob,
> 
> Quick Google search threw up;
> 
> $str = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a
> href=\"\\0\">\\0</a>", $str); 
> 
> at http://www.liamdelahunty.com/tips/php_convert_url_to_link.php
> 
> which an equally quick test here confirms seems to perform what I think
> you want ;-)
> 
> Cheers
> Steve
> 
>> I've got a bulletin board system that i've written and use with my  
>> clients, and I'd like to add another feature that is missing.
>>
>> When someone posts and includes a URL, it would be great if somehow  
>> this URL would automatically be made into a clickable link, a la Mac  
>> Mail or other HTML mail programs.
>>
>> I'm suspecting that the only way is for me to write code that spots  
>> URLs and automatically reformats it to make into a link. Is there an  
>> easier way? Is there a PHP encoding command that would take
>>
>> here is a link to http://www.cnn.com and turn it into "here is a link  
>> to" <a href="http://www.cnn.com">http://www.cnn.com</a>
>>
>> Any suggestions most welcome. If anyone's interested, you can see the  
>> BBS in action at Crystal Gayle's site, which is http:// 
>> www.crystalgayle.com/gayleforce.php
>>
>> Thanks,
>>
>> Bob Patin
>> Longterm Solutions
>> bob at longtermsolutions.com
>> 615-333-6858
>> http://www.longtermsolutions.com
>>
>>    CONTACT US VIA INSTANT MESSAGING:
>>       AIM or iChat: longterm1954
>>       Yahoo: longterm_solutions
>>       MSN: tech at longtermsolutions.com
>>       ICQ: 159333060
>>
>>
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
> 
> 
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
> 



More information about the FX.php_List mailing list