27-05-2008, 10:35 PM
Code PHP :
<?php
function BBCode()
{
var text = document.getElementById('txt').value;
search = new Array(
/[img](.*?)=1[/img]/ig,
/\[email\](([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+))\[\/email\]/ig,
/\[b\](.*?)\[\/b\]/ig,
/\[url\](http:\/\/[^ \\"nrt<]*?)[/url]/ig);
replace = new Array(
"<img src=\"$1\" alt=\"An image\">",
"<a href=\"mailto:$1\">$1</a>",
"<b>$1</b>",
"<a href=\"$1\" target=\"blank\">$1</a>");
for(i = 0; i < search.length; i++) {
text = text.replace(search[i],replace[i]);
};
alert(text);
return;
}