[php]script เขียน BB CODE

PHP Result Center PHP Result Center เป็นหมวด ที่ไว้รวบรวม โปรแกรม Code php Javascript CSS CMS

Moderators: mindphp, ผู้ดูแลกระดาน

PHP Full Member
PHP Full Member
Posts: 32
Joined: 25/10/2010 5:05 pm

[php]script เขียน BB CODE

Post by gangwell »

function bbcode_format ($str) {
// $str = htmlentities($str); ภาษาไทยจะเพี้ยน
$str = htmlspecialchars($str);

$simple_search = array(
//added line break
//added textarea for code presentation
//added pre class for code presentation
//added paragraph

$simple_replace = array(
//added line break
'<br />',
// added nofollow to prevent spam
'<a href="$1" rel="nofollow" title="$2 - $1" target="_blank">$2</a>',
'<a href="$1" rel="nofollow" title="$1" target="_blank">$1</a>',
'<div style="text-align: $1;">$2</div>',
//added alt attribute for validation
'<img src="$1" alt="" />',
'<a href="mailto:$1" target="_blank">$2</a>',
'<a href="mailto:$1" target="_blank">$1</a>',
'<span style="font-family: $1;">$2</span>',
'<span style="font-size: $1;">$2</span>',
'<span style="color: $1;">$2</span>',
//added textarea for code presentation
'<textarea class="code_container" rows="30" cols="70">$1</textarea>',
//added pre class for code presentation
'<pre class="code">$1</pre>',
//added paragraph

// Do simple BBCode's
$str = preg_replace ($simple_search, $simple_replace, $str);

// Do <blockquote> BBCode
$str = bbcode_quote ($str);

return $str;

function bbcode_quote ($str) {
//added div and class for quotes
$open = '<blockquote><div class="quote">';
$close = '</div></blockquote>';

// How often is the open tag?
preg_match_all ('/\[quote\]/i', $str, $matches);
$opentags = count($matches['0']);

// How often is the close tag?
preg_match_all ('/\[\/quote\]/i', $str, $matches);
$closetags = count($matches['0']);

// Check how many tags have been unclosed
// And add the unclosing tag at the end of the message
$unclosed = $opentags - $closetags;
for ($i = 0; $i < $unclosed; $i++) {
$str .= '</div></blockquote>';

// Do replacement
$str = str_replace ('[' . 'quote]', $open, $str);
$str = str_replace ('[/' . 'quote]', $close, $str);

return $str;
เกมส์ สนุกๆมันส์ๆเล่นฟรีจ้า

  • Similar Topics
    Last post

Return to “Free PHP Code Download script”

Who is online

Users browsing this forum: No registered users and 1 guest