Retourner au contenu associé (entrée de forum : Je suis nul en expression reguliere :()
Posté par jlh le 11 septembre 2008 à 22:39. En réponse au message Je suis nul en expression reguliere :(. Évalué à 1.
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
[^] # Re: Quelque chose comme ...
Posté par jlh . En réponse au message Je suis nul en expression reguliere :(. Évalué à 1.
function bb_decode($txt) {
$title_reg = "/\[title\](.*?)\[\/title\]/";
$title_rep = "<span style='font-weight: bold; text-decoration: underline;'>\1円</span>";
$txt = preg_replace($title_reg, $title_rep, $txt);
$bold_reg = "/\[b\](.*?)\[\/b\]/";
$bold_rep = "<span style='font-weight: bold;'>\1円\</span>";
$txt = preg_replace($bold_reg, $bold_rep, $txt);
$underline_reg = "/\[u\](.*?)\[\/u\]/";
$underline_rep = "<span style='text-decoration: underline;'>\1円</span>";
$txt = preg_replace($underline_reg, $underline_rep, $txt);
$italic_reg = "/\[i\](.*?)\[\/i\]/";
$italic_rep = "<span style='font-style: italic;'>\1円</span>";
$txt = preg_replace($italic_reg, $italic_rep, $txt);
$email_reg = "/\[email\]([.\s]*?)\[\/email\]/";
$email_rep = "<a href='\1円'>\1円</a>";
$txt = preg_replace($email_reg, $email_rep, $txt);
$url_reg = "/\[url\](.*?)\[\/url\]/";
$url_rep = "<a href='\1円'>\1円</a>";
$txt = preg_replace($url_reg, $url_rep, $txt);
$color_rep = "<span style='color: \1円;'>\2円</span>";
$color_reg = "/\[color=([a-z]+?|\#[0-9a-fA-F]{6})\](.*?)\[\/color\]/";
$txt = preg_replace($color_reg, $color_rep, $txt);
# nettoyage des balises incomplètes
$balise_reg = "/\[\/?(title|b|u|i|email|url|color(=(.+?))?)\]/";
$txt = preg_replace($balise_reg, "", $txt);
return($txt);
}
Ça n'est pas complet, mais l'idée est là et ça semble fonctionner sur les quelques essais que j'ai fait.