How do I parse all URLs in some text so they become hyperlinks instead of just being text URLs
Parsing URLs
Collapse
X
-
Tags: None
-
PHP Code:// HYPERLINKS \[url="http://xxx"\]yyy\[/url\]
$string = preg_replace("#\\[url="(ftp://|https://|http://|mailto:)(.*)"\\](.*)\\[/url\\]#U","<a href=\"\\\\1\\\\2\" target=_blank>\\\\3</a>",$string);
// HYPERLINKS \[url="xxx"\]yyy\[/url\]
$string = preg_replace("#\\[url="(.*)"\\](.*)\\[/url\\]#U","<a href=\"http://\\\\1\" target=_blank>\\\\2</a>",$string);
// HYPERLINKS \[url=http://xxx\]yyy\[/url\]
$string = preg_replace("#\\[url=(\ftp://\https://|http://|mailto:)(.*)\\](.*)\\[/url\\]#U","<a href=\"\\\\1\\\\2\" target=_blank>\\\\3</a>",$string);
// HYPERLINKS \[url=xxx\]yyy\[/url\]
$string = preg_replace("#\\[url=(.*)\\](.*)\\[/url\\]#U","<a href=\"http://\\\\1\" target=_blank>\\\\2</a>",$string);
// HYPERLINKS \[url\]http://xxx\[/url\]
$string = preg_replace("#\\[url\\](ftp://|https://|http://|mailto:)(.*)\\[/url\\]#U","<a href=\"\\\\1\\\\2\" target=_blank>\\\\2</a>",$string);
// HYPERLINKS \[url\]xxx\[/url\]
$string = preg_replace("#\\[url\\](.*)\\[/url\\]#U","<a href=\"http://\\\\1\" target=_blank>\\\\1</a>",$string);
-
mark that only deals with having [url] tags... he is asking to parse all urls in text with or without custom tags...
Of course, stevie, you can easily modify the preg_replace code mark has provided you with to do what you want
I would suggest looking up preg and ereg functions in the php manual because they are some of the most useful parsing tools around.Last edited by Conscience; Thu 23 May '02, 1:11pm.ConsComment
-
/me slaps self
Sorry, forgot.
I've answered this question before so I tried to search for those threads. I couldn't find them.
Play with the above code for a while. Let me know if you need me to go looking for that other stuff again.Comment
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Comment