^^ ich möchte ein newssystem schreiben und dort soll man sowas wie das mit "[ URL ]" [eigentlich brauch ich nur das für links] im codeschnipsel bereich gibts zwar sowas aber das gefällt mir ned!! :P
SOFARJOAT
SOFARJOAT
$search[]="/\{B}(.*)\{\/B}/siU";
$replace[]="<b>\\1</b>";
$search[]="/\{i}(.*)\{\/i}/siU";
$replace[]="<i>\\1</i>";
$search[]="/([^]_a-z0-9-="'\/])((https?|ftp):\/\/|www\.)([^ \r\n\(\)\*\^\$!`"'\|\[\]\{\};<>]*)/si";
$replace[]="\\1<a href='\\2\\4'>\\2\\4</a>";
$search[]="/\{url}([^"]*)\{\/url\}/siU";
$replace[]="<a href="\\1" target="_blank">\\1</a>";
$search[]="/\{url=(['"]?)([^"']*)\1}(.*)\{\/url\}/siU";
$replace[]="<a href="\\2" target="_blank">\\3</a>";
$text = "hallo {B}fett{/B} <br> {ur}]http://www.yahoo.de{/url} <br> ";
$text .= "{url=http://www.web.de}[url]http://www.web.de[/url]{/url} <br> ";
$text .= "{i}kursiv{/I} <br> ";
$text .= "{B}nochmal fett{/B} <br> dd <br> ";
$text .= "{url}link{/url}";
echo parse($text);
function parse($text)
{
global $search,$replace;
reset($search);
reset($replace);
$text = preg_replace($search,$replace,$text);
return $text;
}
function ubb($msg)
{
global $link;
$msg = str_replace("[hr]","<hr>",$msg);
$msg = str_replace("[b]","<b>",$msg);
$msg = str_replace("[/b]","</b>",$msg);
$msg = str_replace("[i]","<i>",$msg);
$msg = str_replace("[/i]","</i>",$msg);
$msg = str_replace("[img]","<image border=0 src=",$msg);
$msg = str_replace("[/img]",">",$msg);
// [URL]
$msg=eregi_replace("\\[url\\]www.([^\\[]*)\\[/url\\]","<a href=\"http://www.\\1\" target=_blank>\\1</a>",$msg);
$msg=eregi_replace("\\[url\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=_blank>\\1</a>",$msg);
// [URL=
#$msg=eregi_replace("\\[url=\"([^\"]*)\"\\]([^\\[]*)\\[\\/url\\]","<a href=\"\\1\" target=_blank>\\2</a>",$msg);
$msg=eregi_replace("\\[url=([^\"]*)\\]([^\\[]*)\\[\\/url\\]","<a href=\"\\1\" target=_blank>\\2</a>",$msg);
// [quote]
$msg=eregi_replace("\\[quote\\]([^\\[]*)\\[/quote\\]","<BLOCKQUOTE><font size=\"1\" face=\"Verdana, Arial\">[Quote:]</font><hr><i>\\1</i><hr></BLOCKQUOTE>",$msg);
//[code]
$msg=eregi_replace("\\[code\\]([^\\[]*)\\[/code\\]","<pre>\\1</pre>",$msg);
$msg=eregi_replace("\\[email\\]([^\\[]*)\\[/email\\]","<a href=\"mailto:\\1\">\\1</a>",$msg);
return $msg;
}
$text = "Hallo schaut mal auf [ url]http://www.phpundperl.de[/url ].";
$text = ubb($text);
print $text;
<? $search[]="/\[B](.*)\[\/B]/siU"; $replace[]="<b>\\1</b>"; $search[]="/\[i](.*)\[\/i]/siU"; $replace[]="<i>\\1</i>"; $search[]="/([^]_a-z0-9-=\"'\/])((https?|ftp):\/\/|www\.)([^ \r\n\(\)\*\^\$!`\"'\|\[\]\{\};<>]*)/si"; $replace[]="\\1<a href='\\2\\4' target='_blank'>\\2\\4</a>"; $search[]="/\[url]([^\"]*)\[\/url\]/siU"; $replace[]="<a href='\\1' target='_blank'>\\1</a>"; $search[]="/\[url=(['\"]?)([^\"']*)\\1](.*)\[\/url\]/siU"; $replace[]="<a href='\\1' target='_blank'>\\2</a>"; echo parse($text); function parse($text) { global $search,$replace; reset($search); reset($replace); $text = preg_replace($search,$replace,$text); return $text; } require ("contact.php3"); //--- DB AUSWÄHLEN ------------------------------------------- $news = mysql_query("select * from news order by id DESC"); while ( $newsanzeigen= mysql_fetch_array( $news ) ) { ?> <div align="center"> <center> <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="60%" id="AutoNumber2"> <tr> <td width="17%"><font size="5"><? print "". $newsanzeigen[time] .""; ?></font></td> <td width="46%"><font face="Verdana" size="4"><? print "". $newsanzeigen[titel] .""; ?></font></td> </tr> <tr> <td width="63%" colspan="2"><br> <? $text = $newsanzeigen[text]; echo $text; ?></td> </tr> </table> <br><p><br> <? } ?>
$msg=eregi_replace("\[code\]([^\[]*)\[/code\]","<pre>\1</pre>",$msg); $msg=eregi_replace("\[email\]([^\[]*)\[/email\]","<a href=\"mailto:\1\">\1</a>",$msg); return $msg; } $text = "Hallo schaut mal auf [url ]http://www.phpundperl.de[ /url]."; // wobei ich diese Leerzeiche netfernt habe bei url und /url $text = ubb($text); print $text; ?>
Kommentar