Soyez le premier à donner votre avis sur cette source.
Snippet vu 3 838 fois - Téléchargée 17 fois
<?php function encode_pbb($chaine) { //liste des remplacement a effectuer dans le text $conv = array( '\[b\](.*?)\[\/b\]' => '<strong>$1</strong>', '\[i\](.*?)\[\/i\]' => '<em>$1</em>', '\[u\](.*?)\[\/u\]' => '<u>$1</u>', '\[center\](.*?)\[\/center\]' => '<div style="text-align:center;">$1</div>', '\[droite\](.*?)\[\/droite\]' => '<div style="text-align:right;">$1</div>', '\[img\](.*?)\[\/img\]' => '<img src="$1" style="width:500px;" class="image"/>', '\[url=([^\]]*)\](.*)\[\/url\]' => '<a href="$1" style="color: #0071bc;" >$2</a>', '\[video\](.*)\[\/video\]' => '<script type="text/javascript" src="video.php?link=$1"></script>', '\[daily\](.*)\[\/daily\]' => '<object width="320" height="245"><param name="movie" value="http://www.dailymotion.com/video/{$1}"></param><param name="allowfullscreen" value="true"></param><embed src="http://www.dailymotion.com/video/{$1}" type="application/x-shockwave-flash" width="320" height="245" allowfullscreen="true"></embed></object>', ); //empêche les balise de s'afficher $chaine = htmlentities($chaine,ENT_QUOTES,'iso-8859-1'); //remplacer les balise pbb code par des balise html foreach($conv as $k=>$v) { $chaine = preg_replace('/'.$k.'/',$v,$chaine); } return $chaine; } ?>
public static function bbcode2html($text){
$text = preg_replace('!\[quote\](.+)\/quote\!isU', '
Citation :
$1
', $text);
$text = preg_replace("!\[quote\=(.+)\](.+)\[\/quote\]!isU", "
$1 :
$2
", $text);
$text = preg_replace('!\[b\](.+)\/b\!isU', '$1', $text);
$text = preg_replace('!\[i\](.+)\/i\!isU', '$1', $text);
$text = preg_replace('!\[u\](.+)\/u\!isU', '$1', $text);
//$text = preg_replace('!\[center\](.+)\/center\!isU', '$1
', $text);
//$text = preg_replace('!\[right\](.+)\/right\!isU', '$1
', $text);
//$text = preg_replace('!\[left\](.+)\/left\!isU', '$1
', $text);
//$text = preg_replace('!\[titre\](.+)\/titre\!isU', '$1
',$text);
//$text = preg_replace('!\[email\](.+)\/email\!isU', '["mailto:$1">$1',$text);
//$text = preg_replace('!\[img\](.+)\/img\!isU', '',$text);
$text = preg_replace('!\[url\](.+)\/url\!isU', '$1',$text);
$text = preg_replace("!\[url=([^\]]+)\](.+)\/url\!Ui","$2",$text);
$text = preg_replace("!\[color=([^\]]+)\](.+)\[\/color\]!mi","$2",$text);
$text = preg_replace("!\[list\](.+)\/list\!isU","
$1
",$text);
//$text = preg_replace("!\[list=([^\]]+)\](.+)\/list\!isU","
$2
",$text);
$text = preg_replace("!\[\*\](.+)(?=(\[\*\]|
))!isU"," * $1
",$text);
$text = preg_replace('!\[code\](.+)\/code\!isU', '$1
', $text);
return(nl2br($text));
}
j'ai mis en commentaires les tags que je n'utilise pas sur mon site (parce que ça doit être assez gourmand l'accumulation de preg_replace)
class StringHelper{
[...]
public static function bbcode2html($text){
$text = preg_replace('!\[quote\](.+)\/quote\!isU', '
Citation :
$1
', $text);
$text = preg_replace("!\[quote\=(.+)\](.+)\[\/quote\]!isU", "
$1 :
$2
", $text);
$text = preg_replace('!\[b\](.+)\/b\!isU', '$1', $text);
$text = preg_replace('!\[i\](.+)\/i\!isU', '$1', $text);
$text = preg_replace('!\[u\](.+)\/u\!isU', '$1', $text);
//$text = preg_replace('!\[center\](.+)\/center\!isU', '$1
', $text);
//$text = preg_replace('!\[right\](.+)\/right\!isU', '$1
', $text);
//$text = preg_replace('!\[left\](.+)\/left\!isU', '$1
', $text);
//$text = preg_replace('!\[titre\](.+)\/titre\!isU', '$1
',$text);
//$text = preg_replace('!\[email\](.+)\/email\!isU', '["mailto:$1">$1',$text);
//$text = preg_replace('!\[img\](.+)\/img\!isU', '',$text);
$text = preg_replace('!\[url\](.+)\/url\!isU', '$1',$text);
$text = preg_replace("!\[url=([^\]]+)\](.+)\/url\!Ui","",$text);
//$text = str_replace ( '/size' , '' , $text );
$text = preg_replace("!\[color=([^\]]+)\](.+)\[\/color\]!mi","$2",$text);
//$text = str_replace ( '/color' , '</color>' , $text );
$text = preg_replace("!\[list\](.+)\/list\!isU","
$1
",$text);
//$text = preg_replace("!\[list=([^\]]+)\](.+)\/list\!isU","
$2
",$text);
$text = preg_replace("!\[\*\](.+)(?=(\[\*\]|
))!isU"," * $1
",$text);
//$text = str_replace(' ', '
', $text);
return(nl2br($text));
}
}
JJDAI
Serait-il possible de compléter ta liste ?
Pour ca, va voir sur 'http://fr.wikipedia.org/wiki/BBCode'
Merci et bon courage
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.