PHPに段落を検出させ、追加および解析させるにはどうすればよいですか
HTML出力用のタグ?
bbcode をサポートするブログを作成していますが、まだ
ブログ投稿の HTML 出力のタグ。PHPを検出して追加するにはどうすればよいですか
出力のタグ?
私は現在、いくつかの基本的なbbcodeとGeSHiコードを解析するためにこのコードを持っています:
<?php
function code($match) {
require_once './class/geshi/geshi.php';
$geshi = new GeSHi($match[2], $match[1]);
return $geshi->parse_code();
}
function bbcode($input) {
$input = strip_tags($input);
$input = htmlentities($input);
$bbcodes = array(
"/\[b\](.*?)\[\/b\]/is" => "<b>$1</b>",
"/\[u\](.*?)\[\/u\]/" => "<u>$1</u>",
"/\[i\](.*?)\[\/i\]/" => "<i>$1</i>",
"/\[d\](.*?)\[\/d\]/" => "<del>$1</del>",
"/\[url=(.*?)\](.*?)\[\/url\]/" => "<a href='$1'>$2</a>"
);
$input = preg_replace(array_keys($bbcodes), array_values($bbcodes), $input);
//Check for code and add GeSHi:
$input = preg_replace_callback('~\[code=(.*?)\](.*?)\[\/code\]~is', 'code', $input);
return $input;
}
?>
ユーザーがテキストエリアで次の例を送信した場合:
This is [b]bold and [i]italic[/i][/b].
This is some [u]PHP[/u] code:
[code=php]
echo 'Hello world!';
[/code]
That's all folk!
HTML 出力は次のとおりです。
This is <b>bold and <i>italic</i></b>.
This is some <u>PHP</u> code:
<pre class="php" style="font-family:monospace;">
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Hello world!'</span><span style="color: #339933;">;</span>
</pre>
That's all folk!
...p タグなし。では、この機能を追加するにはどうすればよいでしょうか。