le 23/11/2003 à 16:17
gos77
Voila G voulu me faire une class bbcode mais sa fonctionne pas :
Les liens de l'exemple pointe vers http://1
Les liens de l'exemple pointe vers http://1
class bbcode {
var $txt;
function bbcode ($txt) {
$txt = preg_replace ("`\[LIEN\](.+?(?=\[/LIEN\]))\[/LIEN\]`i",$this->bbcode_lien('\\1'), $txt);
$txt = preg_replace ("`\[MAIL\](.+?(?=\[/MAIL\]))\[/MAIL\]`i","<a href=mailto:\\1> \\1 </a>", $txt);
$txt = preg_replace ("`\[B\](.+?(?=\[/LIEN\]))\[/B\]`i",'<strong>\\1</strong>', $txt);
$txt = preg_replace ("`\[I\](.+?(?=\[/I\]))\[/I\]`i",'<em> \\1 </em>', $txt);
$txt = preg_replace ("`\[U\](.+?(?=\[/U\]))\[/U\]`i",'<u> \\1 </u>', $txt);
$txt = preg_replace ("`\[S\](.+?(?=\[/S\]))\[/S\]`i",'<s> \\1 </s>', $txt);
$this->txt = $txt;
}
function bbcode_lien ($url) {
if (preg_match ('`^http://`', $url[1])) {
return '<a href="'.$url[1].'" target="_blank">'.$url[1].'</a>';
}
else {
return '<a href="http://'. $url[1] .'" target="_blank">'. $url[1] .'</a>';
}
}
}
$ab = new bbcode ("texteivb/http://azmailitaliquesoulignerbarré");
echo $ab->txt;
var $txt;
function bbcode ($txt) {
$txt = preg_replace ("`\[LIEN\](.+?(?=\[/LIEN\]))\[/LIEN\]`i",$this->bbcode_lien('\\1'), $txt);
$txt = preg_replace ("`\[MAIL\](.+?(?=\[/MAIL\]))\[/MAIL\]`i","<a href=mailto:\\1> \\1 </a>", $txt);
$txt = preg_replace ("`\[B\](.+?(?=\[/LIEN\]))\[/B\]`i",'<strong>\\1</strong>', $txt);
$txt = preg_replace ("`\[I\](.+?(?=\[/I\]))\[/I\]`i",'<em> \\1 </em>', $txt);
$txt = preg_replace ("`\[U\](.+?(?=\[/U\]))\[/U\]`i",'<u> \\1 </u>', $txt);
$txt = preg_replace ("`\[S\](.+?(?=\[/S\]))\[/S\]`i",'<s> \\1 </s>', $txt);
$this->txt = $txt;
}
function bbcode_lien ($url) {
if (preg_match ('`^http://`', $url[1])) {
return '<a href="'.$url[1].'" target="_blank">'.$url[1].'</a>';
}
else {
return '<a href="http://'. $url[1] .'" target="_blank">'. $url[1] .'</a>';
}
}
}
$ab = new bbcode ("texteivb/http://azmailitaliquesoulignerbarré");
echo $ab->txt;