|
|
|
|
|
|
Lørdag, 10. Maj 2008 Kl. 15:11
Tags:
|
Her er en funktion der kan lave URLs i en streng om til rigtige links. Godt at have, hvis man fx skal lave et forum :-)
<?
/**
* Replaces tekstlinks from a string with a html anchor-tag.
* $text = the string
* $attrs = additional attribtues to the anchor-tag
@author Theis Iversen
**/
function text_url($text, $attrs) {
return preg_replace(
array("#<a href='www\.#", "#(\s) #"),
array("<a href='http://www.", "\\1"),
preg_replace(
"¤(^|[\s,\"'({[]|"|')([a-z]+:/?/?|(www\.))([^\s/]+)(/[^\s]*)?(([!.?,)}\"'\]]|"|')?(\s|$))¤Ui",
"\\1<a href='\\2\\4\\5' $attrs>\\3\\4</a>\\6",
preg_replace(
"#\s#",
"\\0 ",
$text
)
)
);
}
$text = "http://www.test.dk/
Alm link: http://www.dr.dk.
Spørgsmål: http://ekstrabladet.dk/flash/udlandkendte/article1005754.ece?
Https: https://www.sikkerpånettet.dk!
http://www.andeby.dk/ - Min hjemmeby
FTP og andet: ftp://anders@and:andeby.dk \"mms:stream.video-og-musik/?yndlingssang=1\" 'mms:stream.video-og-musik/?yndlingssang=2'
Uden protokol: www.anders.dk www.andersine.dk/?trackinglink=400&noget=andet
I parantes: (mailto:anders@and.dk)";
print nl2br(text_url(htmlentities($text, ENT_QUOTES),"target='_blank' class='default'"));
?>
Rating
3,00 stjerner fra 1 bruger
Log ind for at rate denne blog
|
|
|
|
|
|
|
|
|
Kommentarer