bbcode et class

Répondre
gos77
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
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;
Vive le PHP Hypertext Processor...
gos77
le 23/11/2003 à 16:21
gos77
pardon :
<?
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>';
}
}
}

//on test
$ab = new bbcode ("texteivb/http://azmailitaliquesoulignerbarré");
echo $ab->txt;
?>
Vive le PHP Hypertext Processor...
gos77
le 23/11/2003 à 16:23
gos77
repardon : (si tu peux la GLOBULE supprime les messages précédents, sa fais pas pros)
<?
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>';
}
}
}

//on test
$ab = new bbcode ("texteivb/http://azmailitaliquesoulignerbarré");
echo $ab->txt;
?>
Vive le PHP Hypertext Processor...
Répondre

Ecrire un message

Votre message vient d'être créé avec succès.
LoadingChargement en cours