Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > คือ ผมทำ class bbcode อะคับ แล้วเจอปัญหา ผมว่า ต้องแก้ไขตรงบันทัดนี้ แต่ยังคิดไม่ออกว่า จะแก้ไขยังงัย เหอๆ



 

คือ ผมทำ class bbcode อะคับ แล้วเจอปัญหา ผมว่า ต้องแก้ไขตรงบันทัดนี้ แต่ยังคิดไม่ออกว่า จะแก้ไขยังงัย เหอๆ

 



Topic : 027465



โพสกระทู้ ( 830 )
บทความ ( 0 )



สถานะออฟไลน์




Code (PHP)
<?php
class bbcode 
{
	/**
	* html list tyle
	*
	* @var array
	*/		
	private $listStyle;

	/**
	* syntag of syntaxHighlighter
	*
	* @var array
	*/		
	private $syntaxHighlighter;

	/**
	* custom BBcode
	*
	* @var array
	*/	
	private $customBBCode;

	/**
	* html Replacement 
	*
	* @var string
	*/	
	private $htmlReplacement;

	/**
	* tag
	*
	* @var string
	*/	
	private $tag;

	/**
	* remove message in code tag
	*
	* @var array
	*/	
	private $removeMSGCodeTag = array('<br />','\n');

	/**
	* class constructor 
	* 
	* @return void
	*/
	public function __construct() 
	{
		$this->listStyle = array('1' => '1','a' => 'a','A' => 'A', 'i' => 'i', 'I' => 'I');

		$this->syntaxHighlighter = array(
											'php' => 'php',
											'js' => 'js',
											'asp' => 'asp',
											'sql' => 'sql',
											'css' => 'css',
											'xml' => 'xml',
											'java' => 'java
											');
		$this->customBBCode = array(
										'1' => array(
														'li'	=>	'<li>'
														),
										'2' => array(
														'b'		=>	'<strong>{message}</strong>',
														'i'		=>	'<em>{message}</em>',
														'u'		=>	'<u>{message}</u>'
														),
										'3' => array(
														'color'	=>	'<span style="color: {option}">{message}</span>',
														'quote' =>	"					
					<div class='quotemessage'>
						<table width='90%' border='0' cellpadding='0' cellspacing='0'>
							<tr>
								<td>
								<div class='quote_title' style='padding:5px; margin:0px;'><b>ข้อความโดย :: {option}</b></div>
								<div class='quotecontent' style='padding:5px; margin:0px;'>{message}</div>
								</td>
							</tr>
						</table> 
					</div>"
														)
										);
	}


	/**
	* array to remove message in code text
	*
	* @param	array $removeMSGCodeTag (array('<br />','\n'))	
	* 
	* @return	void
	*/
	public function setremoveMSGCodeTag($removeMSGCodeTag) 
	{
		$this->removeMSGCodeTag = $removeMSGCodeTag;
	}

	/**
	* add new tag
	*
	* @param	string $type (s, d, t)
	*				1 : single tag
	*				2 : double tag
	*				3 : tripple tag
	* @param	string $tag ( video )
	* @param	string $html
	* 
	* @return	void
	*/
	public function addTag($type, $tag, $html) 
	{
		$this->customBBCode[$type][$tag] = $html;
	}

	/**
	* parse bbcode
	*
	* @param	string $text
	* 
	* @return	string
	*/
	final public function parse($text) 
	{

		if ( count( $this->customBBCode['1'] ) > 0 ) 
		{
			foreach ( $this->customBBCode['1'] AS $tag => $html) 
			{
				$text = preg_replace('#\['.$tag.'\]#si', '<'.$tag.' />', $text);
			}
		}

		if ( count( $this->customBBCode['2'] ) > 0 ) 
		{
			foreach ( $this->customBBCode['2'] AS $tag => $html) 
			{
				$this->htmlReplacement = $html;
				$this->tag = $tag;
				$text = $this->customTag( $text );
			}
		}

		if ( count( $this->customBBCode['3'] ) > 0 ) 
		{
			foreach ( $this->customBBCode['3'] as $tag => $html)
			{
				$this->htmlReplacement = $html;
				$this->tag = $tag;
				$text = $this->customOptionTag( $text );
			}
		}

		$text = self::imgTag($text);
		$text = self::urlTag($text);
		$text = self::emailTag($text);
		$text = $this->listTag($text);
		$text = $this->codeTag($text);

		return $text;
	}

	/**
	* parse img tag
	*
	* @param	string $text
	* 
	* @return	void
	*/
	public static function imgTag( $text )
	{
		return preg_replace('#\[img](.*?)\[/img\]#si', '<img src=\'\\1\' alt="" title="" />', $text);
	}

	/**
	* parse url tag
	*
	* @param	string $text
	* 
	* @return	string
	*/
	public static function urlTag( $text )
	{
		$text = preg_replace('#\[url=(.*?)\](.*?)\[/url\]#si', '<a href=\'\\1\' alt="" title="">\\2</a>', $text);
		$text = preg_replace('#\[link=(.*?)\](.*?)\[/link\]#si', '<a href=\'\\1\' alt="" title="">\\2</a>', $text);
		return $text;
	}

	/**
	* parse url tag
	*
	* @param	string $text
	* 
	* @return	string
	*/
	public static function emailTag( $text )
	{
		$text = preg_replace('#\[email](.*?)\[/email\]#si', '<a href="mailto:\'\\1\'" alt="" title="">\\1</a>', $text);
		return $text;
	}

	/**
	* parse custom tag
	*
	* @param	string $text
	* 
	* @return	string
	*/
	public function customTag( $text )
	{
		return preg_replace_callback('#\[' . $this->tag . '\](.*?)\[/' . $this->tag . '\]#si', array( &$this, 'customTagCallBack' ), $text);
	}

	/**
	* parse custom tag callback
	*
	* @param	string $match
	* 
	* @return	string
	*/
	public function customTagCallBack( $match )
	{
		return str_replace('{message}' ,$match[1], $this->htmlReplacement);
	}

	/**
	* parse custom option tag
	*
	* @param	string $text
	* 
	* @return	string
	*/
	public function customOptionTag( $text )
	{
		return preg_replace_callback('#\[' . $this->tag . '=(.*?)\](.*?)\[/' . $this->tag . '\]#si', array( &$this, 'customOptionTagCallBack' ), $text);
	}

	/**
	* parse custom option tag callback
	*
	* @param	string $match
	* 
	* @return	string
	*/
	public function customOptionTagCallBack( $match )
	{
		$text = str_replace('{message}' ,$match[2], $this->htmlReplacement);
		return str_replace('{option}' ,$match[1], $text);
	}

	/**
	* parse list tag
	*
	* @param	string $text
	* 
	* @return	string
	*/
	public function listTag( $text )
	{
		return preg_replace_callback('#\[list=(.*?)\](.*?)\[/list\]#si', array( &$this, 'listTagCallBack' ), $text);
	}

	/**
	* parse list tag callback
	*
	* @param	string $match
	* 
	* @return	string
	*/
	public function listTagCallBack( $match )
	{
		return '<ol type="' . $this->listStyle[$match[1]] . '">' . $match[2] . '</ol>';
	}

	/**
	* parse code tag
	*
	* @param	string $text
	* 
	* @return	string
	*/
	public function codeTag( $text )
	{
		return preg_replace_callback('#\[code=(.*?)\](.*?)\[/code\]#si', array( &$this, 'codeTagCallBack' ), $text);
	}

	/**
	* parse code tag callback
	*
	* @param	string $match
	* 
	* @return	string
	*/
	public function codeTagCallBack( $match )
	{
		if ( count( $this->removeMSGCodeTag) > 0 )
		{
			foreach ( $this->removeMSGCodeTag AS $value )
			{
				$match[2] = str_replace( $value,'',$match[2] );
			}
		}
		return '<pre class="brush: ' . $this->syntaxHighlighter[$match[1]] . '">' . $match[2] . '</pre>';
	}
}[/code]

คือ ถ้า bbcode ไม่ซ้อนกัน ก็ไม่มีปัญหา แต่มันซ้อนกันเมือไร จบเลย

ผมใช้แบบนี้อะ

/** * parse custom tag * * @param string $text * * @return string */ public function customTag( $text ) { return preg_replace_callback('#\[' . $this->tag . '\](.*?)\[/' . $this->tag . '\]#si', array( &$this, 'customTagCallBack' ), $text); } /** * parse custom tag callback * * @param string $match * * @return string */ public function customTagCallBack( $match ) { return str_replace('{message}' ,$match[1], $this->htmlReplacement); } ?>


สมมุติ

Code
[code][quote='danya']ผมเอง[/quote]


มันไม่มีปัญหา

แต่ถ้า

Code
[quote='num'][quote='danya']ผมเอง[/quote]คุณเองเหรอ[/quote]


จะมีปัญหาทันที

[ quote='num'] เพราะมันไปตัด [ /quote] อันแรก มันไม่ยอมไปตัด [ /quote] อันหลัง

อธิบายอีกที มันจะมองแบบนี้

Code
[quote='num'][quote='danya']ผมเอง[/quote]


แทนที่จะมองแบบนี้

Code
[quote='num'][quote='danya']ผมเอง[/quote]คุณเองเหรอ[/quote]


ผมจะใช้การตรวจสอบอย่างไรดีอะ

Code
reg_replace_callback('#\[' . $this->tag . '\](.*?)\[/' . $this->tag . '\]#si', array( &$this, 'customTagCallBack' ), $text);


ผมว่า ต้องแก้ไขตรงบันทัดนี้ แต่ยังคิดไม่ออกว่า จะแก้ไขยังงัย เหอๆ



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-05-19 08:50:40 By : danya View : 1383 Reply : 6
 

 

No. 1



โพสกระทู้ ( 830 )
บทความ ( 0 )



สถานะออฟไลน์


ผมไปเจอฝรั่งเขาก็เจอปัญหาแบบผมเหมือนกัน

ยังหาวิธีแก้ไม่ได้ 555+

http://www.phpfreaks.com/forums/index.php?topic=239351.0






Date : 2009-05-19 09:01:41 By : danya
 


 

No. 2



โพสกระทู้ ( 830 )
บทความ ( 0 )



สถานะออฟไลน์


มั่วๆ เอา ผมแก้ได้แล้วครับ อิอิ

Code (PHP)
<?php
	public function customOptionTag( $text )
	{
		while( preg_match( "#\[" . $this->tag . "=(.+?)\](.+?)\[/" . $this->tag . "\]#is" , $text ) )
		{
			$text = preg_replace_callback( "#\[" . $this->tag . "=(.+?)\](.+?)\[/" . $this->tag . "\]#is"  , array( &$this, 'customOptionTagCallBack' ), $text );
		}
		return $text;
	}
?>



สรุป

ผมแก้ไขปัญหานี้ได้แล้วครับ อิอิ
Date : 2009-05-19 09:27:55 By : danya
 

 

No. 3

Guest


ติดตรงนี้เหมือนกัน พอลองนำของคุณมาปรับปรุง แก้ได้แล้วครับ ขอบคุณมาก
Date : 2009-10-11 10:31:42 By : Ivetren
 


 

No. 4



โพสกระทู้ ( 1,579 )
บทความ ( 3 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


แล้วอันเดิมที่เอามาผมต้องแก้ตามเพ่ดุนยาเปล่าครับ ต้องเพิ่มโค้ดตรง No.2 นี้เข้าไปหรือแก้ไขอันเดิมครับ
ผมก็นั่งศึกษาโค้ดเพ่ดุนอยู่เหมือนกัน งงบ้างเข้าใจบ้างแต่ก็ไม่กล้าจะมาถามอีกเห็นเพ่ไม่ว่าง ก็เลยต้อง งูๆปลาๆไป อิอิอิอิ
Date : 2009-10-11 10:54:59 By : somparn
 


 

No. 5



โพสกระทู้ ( 830 )
บทความ ( 0 )



สถานะออฟไลน์


เฮ้ยๆๆ

โค้ดนี้ นานแล้วววๆๆๆๆ

โค้ดมันใหม่ ทำงานได้เยอะกว่านี้อีก

คุณ Ivetren ไปขุดมาทำไมอะคับเนีย -*-
Date : 2009-10-11 12:24:45 By : danya
 


 

No. 6



โพสกระทู้ ( 1,579 )
บทความ ( 3 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


อ้าวเวรกำ ลืมดูวันที่ ที่ให้มามันก็ใช้งานได้เป็นอย่างดี 555
Date : 2009-10-11 14:06:05 By : somparn
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : คือ ผมทำ class bbcode อะคับ แล้วเจอปัญหา ผมว่า ต้องแก้ไขตรงบันทัดนี้ แต่ยังคิดไม่ออกว่า จะแก้ไขยังงัย เหอๆ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่