国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP開發(fā)基礎(chǔ)教學(xué)之簡(jiǎn)單的UBB文字編輯器

本節(jié)看不懂的話可以跳過,以後有興趣再來仔細(xì)看

#我們來看一下UBB編輯器。這是網(wǎng)站當(dāng)中常用到的文字處理技術(shù)。因?yàn)槭褂肬BB檔案編輯器,我們指定的格式才能存在。不指定的格式的話,使用者是無法在網(wǎng)站中展現(xiàn)的。

我們來看看效果:

<?php
$string='[b]靜夜思[/b]
[color=Red]李白[/color]
[i]床前明月光[/i]
[u]疑是地上霜[/u]
[i]舉頭望明月[/i]
[u]低頭思故鄉(xiāng)[/u]
';
//匹配UBB字符
$pattern=array(
    '/\[b\](.*)\[\/b\]/i',
    '/\[i\](.*)\[\/i\]/iU',
    '/\[u\](.*?)\[\/u\]/i',
    '/\[color=(.*?)\](.*?)\[\/color\]/',
    );
//需要替換的UBB字符
$replace=array(
    '<b>\1</b><br />',
    '<i>\1</i><br />',
    '<u>\1</u><br />',
    '<font color="\1">\2</font><br />',
    );
//使用正則匹配$string,將$string當(dāng)中的值變?yōu)?replace的效果
$ubb=preg_replace($pattern,$replace,$string);
echo $ubb;
?>

輸出結(jié)果如右所示


繼續(xù)學(xué)習(xí)
||
<?php $string='[b]靜夜思[/b] [color=Red]李白[/color] [i]床前明月光[/i] [u]疑是地上霜[/u] [i]舉頭望明月[/i] [u]低頭思故鄉(xiāng)[/u] '; //匹配UBB字符 $pattern=array( '/\[b\](.*)\[\/b\]/i', '/\[i\](.*)\[\/i\]/iU', '/\[u\](.*?)\[\/u\]/i', '/\[color=(.*?)\](.*?)\[\/color\]/', ); //需要替換的UBB字符 $replace=array( '<b>\\1</b><br />', '<i>\\1</i><br />', '<u>\\1</u><br />', '<font color="\\1">\\2</font><br />', ); //使用正則匹配$string,將$string當(dāng)中的值變?yōu)?replace的效果 $ubb=preg_replace($pattern,$replace,$string); echo $ubb; ?>
提交重置程式碼