Salve a tutti, premetto che ho usato il tasto cerca ma tra discussioni non risposte e quelle risposte non ho trovato ciò che cerco.
Venendo al dunque sto cercando di fare un bbcode in php, ho buttato giù due righe al volo e sono arrivato ad un buon punto
Codice PHP:
<?
function bbcode ($str) {
$htmltags = array(
'/\<b\>(.*?)\<\/b\>/is',
'/\<i\>(.*?)\<\/i\>/is',
'/\<u\>(.*?)\<\/u\>/is',
'/\<ul\>(.*?)\<\/ul\>/is',
'/\<li\>(.*?)\<\/li\>/is',
'/\<img(.*?) src=\"(.*?)\" (.*?)\>/is',
'/\<div style="text-align:(.*?)"\>(.*?)\<\/div\>/is',
'/\<br(.*?)\>/is',
'/\<strong\>(.*?)\<\/strong\>/is',
'/\<a href=\"(.*?)\"(.*?)\>(.*?)\<\/a\>/is',
'/\<a href=\'(.*?)\'(.*?)\>(.*?)\<\/a\>/is',
);
$bbtags = array(
'$1',
'$1',
'$1',
'$1',
'[*]$1[/*]',
'[img]$2[/img]',
'[$1]$2[/$1]',
'\n',
'$1',
'$3',
'$3',
);
$str = preg_replace ($htmltags, $bbtags, $str);
$str = nl2br($str);
return $str;
}
$str = $_POST[text];
echo bbcode($str);
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<textarea name=text></textarea>
<input type="submit" name="submit" value="Vai">
</form>
il mio problema è questo: come posso eliminare tutti gli altri tag che non sono presenti nell'array di ricerca ($htmltags)? ad esempio se qualcuno scrive nella textarea l'attributo <table>, l'output mostrerà una tabella...!
Grazie anticipatamente!