Re: Converting links in strings

From: Date: Tue, 04 Feb 2003 11:36:39 +0000
Subject: Re: Converting links in strings
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-134245@lists.php.net to get a copy of this message
Randum Ian schrieb: > Hi all, > > Please can someone direct me to the correct function that changes > http://www.foo.com to <a > href="http://www.foo.com">http://www.foo.com</a> > for any occurence in a string. > > Cheers, Ian. > do you wish convert a string in a link ??? try: <?php echo "<a href="$string1">$string1</a>"; ?> or a link in a string ? <?php preg_match('/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\//i', $link, $string) ?> with $string[1]; // protocol type (http,https,ftp) $string[2]; // hostname (domain) $string[3]; // port if available like 80 for http ... please be more precise in your question ! -- @ Goetz Lohmann, Germany | Web-Developer & Sys-Admin \/ ------------------------------------------------------ () He's the fellow that people wonder what he does and || why the company needs him, until he goes on vacation.

« previous php.general (#134245) next »