|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
What do i have to do, to do the following:
if somebody pastes a url i.e. http://this address.com, how can i make it into a clickable link when the user submits the form and the message gets displayed on a new page. I am using the following, but it makes the whole string a link. PHP Code:
__________________
regards, Fulton |
|
#2
|
|||
|
|||
|
You'll want to use a regular expression. Here's one that I found on the web for this purpose.
Code:
$output = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "<a href=\"\\1://\\2\\3\" target=\"_blank\" target=\"_new\">\\1://\\2\\3</a>", $strText);
|
|
#3
|
|||
|
|||
|
Thanks for your help i tried the following as a test, but its not working. any ideas?
PHP Code:
|
|
#4
|
|||
|
|||
|
Sorry! I only gave you half of the function
![]() Code:
<?
function createHTML($strText) {
$output = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "<a href=\"\\1://\\2\\3\" target=\"_blank\" target=\"_new\">\\1://\\2\\3</a>", $strText);
$output = eregi_replace("(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a href=\"mailto:\\1\" target=\"_new\">\\1</a>", $output);
$output = nl2br($output);
return $output;
}
$string = "http://www.link_one.com this is a test";
echo createHTML($string);
?>
|
|
#5
|
|||
|
|||
|
Hi, thanks for that it works great, now i need to differentiate between bbcode and a normal http: link.
my code is below. PHP Code:
the function need to be able to check whether each word begins with http or [url] and then do the correct thing. |
|
#6
|
||||
|
||||
|
Doesn't it do that yet?
I haven't checked your function yet, I will implement it myself and test it. It looks good though... Cheers,
__________________
Work to live, don't live to work |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Replace http:// to a URL? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|