Reply to Re: Finding urls and making them hyperlinks

Your name:

Reply:


Posted by John McClumpha on 11/02/89 11:32

On 19 Nov 2005 13:39:46 -0800, laredotornado@zipmail.com wrote:
>I want to take a block of text and add html tags to make hyperlinks
>where hyperlink strings exist. So, if I have a variable
>
>$a = "This is http://www.yahoo.com"
>
>I would like to run that through a function such that the value of $a
>is
>
>"This is <a href='http://www.yahoo.com'>http://www.yahoo.com</a>"

making the following 2 assumptions:

URL begins with " http" (and there is only one instance within $a)
URL contains no spaces

something like the following (untested) code should work - (this can
most likely be optimized and I'd be interested to know how if anyone
can help out):

<?

$a = "This is http://www.yahoo.com";

// break everything to the left of "http"
$MyURL = substr($a, strpos($a, "http"));
$MyIntro = substr($a, 0, strpos($a, "http"));

// remove anything after URL (if existing)
if (strpos($MyURL," ")) { // there is a space in the string (after
URL)
$MyURL = substr($MyURL, 0, strpos($MyURL, " "));
}

$MyOutput = $MyIntro . "<a href=\"" . $MyURL . "\">" . $MyURL .
"</a>";

echo $MyOutput;
?>


--
John McClumpha
Darkness Reigns - http://www.incitegraphics.com.au/darkness/

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация