Changing URL's
Moderator: General Moderators
Changing URL's
Hi!
Do you know with this forum when your put:
[url]http://www.domain.com[/url]
or:
[url=http://www.domain.com]Click Here[/url]
it puts:
<a href="http://www.domain.com" target="_blank">http://www.domain.com</a>
How can I do that?
Thanks
Tech
Do you know with this forum when your put:
[url]http://www.domain.com[/url]
or:
[url=http://www.domain.com]Click Here[/url]
it puts:
<a href="http://www.domain.com" target="_blank">http://www.domain.com</a>
How can I do that?
Thanks
Tech
I wonder... Could it be something like this:

Code: Select all
<?php
$string = str_replace("[url=$url]$title[/url]","<a href="$url" target="_blank">$title</a>",$string);
return $string;
?>there is plenty of example code and it isn't that easy 
e.g. http://www.phpclasses.org/mirrors.html? ... 2F818.html
e.g. http://www.phpclasses.org/mirrors.html? ... 2F818.html
-
superwormy
- Forum Commoner
- Posts: 67
- Joined: Fri Oct 04, 2002 9:25 am
- Location: CT
$newlink = str_replace ("", "<a href=\"", $oldlink);
$newlink = str_replace ("", "\">mylinkname</a>", $newlink);
$newlink = str_replace ("", "\">mylinkname</a>", $newlink);
Thanks wormy but this seems to work:
For [url=http://www.url.com]Link Text[/url]
$text = eregi_replace("\\[url=([^\\[]*)\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=\"_blank\">\\2</a>",$text);
For [url]http://www.url.com[/url]
$text = eregi_replace("\\[url]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=\"_blank\">\\1</a>",$text);
Works well!
Also, with phpBB if you don't put a [url] and [/url] around your links it still makes it a link... how can do this?
Maybe:
$text = eregi_replace("\\http://([^\\[]*)\\","<a href=\"http://\\1\" target=\"_blank\">\\1</a>",$text);
For [url=http://www.url.com]Link Text[/url]
$text = eregi_replace("\\[url=([^\\[]*)\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=\"_blank\">\\2</a>",$text);
For [url]http://www.url.com[/url]
$text = eregi_replace("\\[url]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=\"_blank\">\\1</a>",$text);
Works well!
Also, with phpBB if you don't put a [url] and [/url] around your links it still makes it a link... how can do this?
Maybe:
$text = eregi_replace("\\http://([^\\[]*)\\","<a href=\"http://\\1\" target=\"_blank\">\\1</a>",$text);
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
Heres how I do it (many thanks to phpBB for the approach):
I have a template file, containing something like:
name it like, url.tpl
then have a function:
then have another function:
and one more function 
then:
And that should parse it all! Sorry if its a bit big, but it works.
I have a template file, containing something like:
Code: Select all
<!-- BEGIN url --><a href="{URL}" target="_blank">{DESCRIPTION}</a><!-- END url -->then have a function:
Code: Select all
function opentemplate($template){
$tpl = fread(fopen($template, 'r'), filesize($template));
$tpl = str_replace('\'', '\\\'', $tpl);
$tpl = str_replace('''', '\\''', $tpl);
$tpl = str_replace("\n", '', $tpl);
$tpl = preg_replace('#<!-- BEGIN (.*?) -->(.*?)<!-- END (.*?) -->#', "\n" . '$code_tplsї''\\1''] = ''\\2'';', $tpl);
$code_tpls = array();
eval($tpl);
return $code_tpls;
}Code: Select all
function preparetemplate($code_tpl){
// We do URLs in several different ways..
$code_tplї'url1'] = str_replace('{URL}', '\\1\\2', $code_tplї'url']);
$code_tplї'url1'] = str_replace('{DESCRIPTION}', '\\1\\2', $code_tplї'url1']);
$code_tplї'url2'] = str_replace('{URL}', 'http://\\1', $code_tplї'url']);
$code_tplї'url2'] = str_replace('{DESCRIPTION}', '\\1', $code_tplї'url2']);
$code_tplї'url3'] = str_replace('{URL}', '\\1\\2', $code_tplї'url']);
$code_tplї'url3'] = str_replace('{DESCRIPTION}', '\\3', $code_tplї'url3']);
$code_tplї'url4'] = str_replace('{URL}', 'http://\\1', $code_tplї'url']);
$code_tplї'url4'] = str_replace('{DESCRIPTION}', '\\2', $code_tplї'url4']);
return $code_tpl;
}Code: Select all
function codeparse($text){
$text = " " . $text;
global $code_tpl;
$patterns = array();
$replacements = array();
$patternsї1] = "#\їurl\](їa-z]+?://){1}(їa-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)\ї/url\]#si";
$replacementsї1] = $code_tplї'url1'];
$patternsї2] = "#\їurl\](їa-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)\ї/url\]#si";
$replacementsї2] = $code_tplї'url2'];
$patternsї3] = "#\їurl=(їa-z]+?://){1}(їa-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)\](.*?)\ї/url\]#si";
$replacementsї3] = $code_tplї'url3'];
$patternsї4] = "#\їurl=(їa-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)\](.*?)\ї/url\]#si";
$replacementsї4] = $code_tplї'url4'];
$text = preg_replace($patterns, $replacements, $text);
return trim($text);
}Code: Select all
$code_tpl = opentemplate('url.tpl');
$code_tpl = preparetemplate($code_tpl);
echo codeparse($text);The problem is, I don't use that template system..... But i did get this from phpBB:
Does anyone know why it isn't working?
Code: Select all
<?php
$article = preg_replace("#([\n ])([a-z]+?)://([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)#i", "\\1<a href="\\2://\\3" target="_blank">\\2://\\3</a>", $article);
?>