Click to See Complete Forum and Search --> : Detecting hyperlink/url entered in form


Anon
04-13-2002, 03:56 AM
Hi,

I am hoping someone can help me with this. I have a simple form very similar to this one & I want to be able to create a hyperlink if someone puts in www.whatever.com. Currently, my form results do not display the url as a hyperlink. This form's output goes to an auto email - in the email that goes out I want the url to be a hyperlink people can click. Any help would be GREATLY appreciated. Thanks!

Anon
04-13-2002, 05:07 PM
Hi!
I hope the code comes out the right way.
Taken from:
http://www.koehntopp.de/php/regexp.html#regexp-bauelemente

Credits to Björn Schotte, the Author of this snipped.

$str is the input.
Call the function within your form validation after submit.

U can use this like:

$link = replace_uri($str);

$link now contains the orig. text and all converted URIs.

Volker
/**
* replace URIs with appropriate HTML code to be clickable.
*/
function replace_uri($str) {
$pattern = '#(^|[^\"=]{1})(http://|ftp://|mailto:|news:)([^\s<>]+)([\s\n<>]|$)#sm';
return preg_replace($pattern,"\\1<a href=\"\\2\\3\"><u>\\2\\3</u></a>\\4",$str);
}

Anon
08-12-2002, 05:36 PM
What I am trying to do is similar but I want to change a url and give it a different name so instead of putting:

http://somedomain.com and making the actual URL a link I want it to take

http://somewomain.com LINKNAME and make it

<a href="http://somedomain.com">LINKNAME</a>

Any ideas?

I know how to find the urls abut not assign it a link name. I've got one in PERL that the input is

URL LINKNAME and it will take the linkname and make it a link with the URL as the linkurl.