Zrobiłem to tak :
Kod
<?php
// Cuts off long URLs at $url_length, and appends "..."
function reduceurl($url, $url_length) {
$reduced_url = substr($url, 0, $url_length);
if (strlen($url) > $url_length) $reduced_url .= '...';
return $reduced_url;
}
// Makes URLs with brackets into links
// The regex searches for "<a target="_blank" rel="nofollow" href="http:///">http://</a>" or equivalent, then various character possibilities (I don't know if it might be
possible to exploit this if more characters were allowed). The "e" after the regex allows the reduceurl() to be evaluated.
function url2link($linktext) {
$linktext = preg_replace("#\[(([a-zA-Z]+://)([a-zA-Z0-9?&%.;:/=+_-]*))\]#e", "'<a href=\"$1\" target=\"_blank\">' . reduceurl(\"$3\", 30) . '</a>'", $linktext);
return $linktext;
}
$nowaTresc = url2link(Tekst + http://przykladowylink.pl);
echo $nowaTresc
?>
I jeśli w miejsce zmiennej $tekst wstawię sam tekst bez linków które mają być zamienione to jest ok, ale jak wstawię już jakiś link do zamienienia to następujący błąd :
Kod
[b]Parse error[/b]: syntax error, unexpected '<', expecting ')' in [b]/home/test/domains/test.pl/public_html/zamiana.php[/b] on line [b]18[/b]
Pozdrawiam i z góry dziękuje za pomoc .