|  | 
	                
  
    | 
	 
        จะเขียน bbcode ยังไงดีเมื่อเจอ code iframe ของ google map     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | พอดีเจอรุ่นน้องที่มหาลัยถามมานะครับ แต่ผมก็ดันตอบไม่ได้ (อายไปเลย) 
 เริ่มเลยละกัน
 
 พอดีรุ่นน้องมันถามว่าจะเอาลิ้งแผนที่ของ google map มาโพสลงในกระทู้ยังไง ให้มันขึ้นเป็นแผนที่อ่ะครับ
 
 ภาพตอนกำลัง โพส
 
  
 หลังโพสเสร็จแล้ว
 
  
 อย่างที่เห็นมันออกมาเป็น Code แบบนี้เลย จะทำยังไงให้มันออกมาเป็น แผนที่ ได้เลยอ่ะครับ
 
 bbcode ที่ใช้อยู่ก็ตัวนิ เห็นรุ่นน้องบอกว่าเอามาจากที่นี้แหละ ไอผมก็ไม่ได้เทพอ่ะไรมาก เลยไม่รู้จะช่วยไง เลยมาโพสถามให้แทน เกิดทำได้ ตัวเองก็จะได้รู้ไปด้วยว่าต้องทำไง อิอิ
 
 Code (PHP)
 
 <?php
function bbcode_format ($str) {  
   // $str = htmlentities($str);  ÀÒÉÒä·Â¨Ðà¾Õé¹
      $str = nl2br(htmlspecialchars($str));
  
    $simple_search = array(  
                //added line break  
                '/\[br\]/is',  
                '/\[b\](.*?)\[\/b\]/is',  
                '/\[i\](.*?)\[\/i\]/is',  
                '/\[u\](.*?)\[\/u\]/is',  
                '/\[url\=(.*?)\](.*?)\[\/url\]/is',  
                '/\[url\](.*?)\[\/url\]/is',  
                '/\[align\=(left|center|right)\](.*?)\[\/align\]/is',  
                '/\[img\](.*?)\[\/img\]/is',  
                '/\[mail\=(.*?)\](.*?)\[\/mail\]/is',  
                '/\[mail\](.*?)\[\/mail\]/is',  
                '/\[font\=(.*?)\](.*?)\[\/font\]/is',  
                '/\[size\=(.*?)\](.*?)\[\/size\]/is',  
                '/\[color\=(.*?)\](.*?)\[\/color\]/is',  
                  //added textarea for code presentation  
               '/\[codearea\](.*?)\[\/codearea\]/is',  
                 //added pre class for code presentation  
              '/\[code\](.*?)\[\/code\]/is',  
                //added paragraph  
              '/\[p\](.*?)\[\/p\]/is',  
                );  
  
    $simple_replace = array(  
				//added line break  
               '<br />',  
                '<strong>$1</strong>',  
                '<em>$1</em>',  
                '<u>$1</u>',  
				// 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  
				'<p>$1</p>', 				
                );  
  
    // Do simple BBCode's  
    $str = preg_replace ($simple_search, $simple_replace, $str);  
  
    // Do <blockquote> BBCode  
    $str = bbcode_quote ($str);  
  
    $str = clickable_link($str);
  
    return $str;  
}  
  
  
  
function bbcode_quote ($str) {  
    //added div and class for quotes  
    $open = '<blockquote><div class="Mainmenu">quote</div><table width="90%" height="56" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000"><tr><td class="text">';  
    $close = '</td></tr></table></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;  
} 
function clickable_link($str)  // This function is to create clickable link when we post some normal text link
{
# this functions deserves credit to the fine folks at phpbb.com
$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $str);
// pad it with a space so we can match things at the start of the 1st line.
$ret = ' ' . $str;
// matches an "xxxx://yyyy" URL at the start of a line, or after a space.
// xxxx can only be alpha characters.
// yyyy is anything up to the first space, newline, comma, double quote or <
//$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" rel=\"nofollow\" target=\"_blank\">\\2</a>", $ret);
// matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing
// Must contain at least 2 dots. xxxx contains either alphanum, or "-"
// zzzz is optional.. will contain everything up to the first space, newline,
// comma, double quote or <.
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
// matches an email@domain type address at the start of a line, or after a space.
// Note: Only the followed chars are valid; alphanums, "-", "_" and or ".".
$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
// Remove our padding..
$ret = substr($ret, 1);
return $ret;
}
?>
 รบกวนผู้รู้ช่วยตอบทีนะครับ โดนน้องตามถาม 3 วันละ เจอหน้าทีไรถามตลอด = =a
 
 
 
 Tag : PHP, MySQL
 
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2012-07-11 20:09:06 | By :
                          hotreplay | View :
                          1926 | Reply :
                          16 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | รู้สึก CkEditor มันมี Mode สำหรับ BBCode มาให้เลยน่ะครับ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-07-11 21:39:29 | By :
                            mr.win |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ถ้าเป็นผม ผมจะเอาค่าตั้งแต่ https จนถึง source=embed มาครับ 
 [maps]https จนถึง source=embed[/map]
 
 
 แล้วหน้าฟังก์ชั่นก็ก๊อปโค้จริงมาทั้งหมด แล้วเอาค่าข้างบนออก แล้วแทนที่ด้วย $1 ตามค่า regular expression
 
 Code (PHP)
 
 $simple_search = array(
'/\[maps\](.*?)\[\/maps\]/is',
);
 
 Code (PHP)
 
 $simple_replace = array( 
<iframe bl bla bla bla src="$1"></frame> bla bla bla <a href="$1"> </a>
);
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-07-11 23:28:10 | By :
                            Pine |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ผมทำแบบนี้ตั้งแต่แกะ BBCode ของ phpBB มาเลยครับ ทำแท็ก youtube ลงเพลง ตามแต่จะคิดออกครับ ฮ่าๆๆ 
 ตัว phpBB จะง่าย มันจะมีไฟล์ให้เราเพิ่มแท็กเองครับ แล้วค่อยมาทำให้มันตรงกันครับ แต่ CkEditor ยังไม่เคยลองเลย
  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-07-12 01:09:33 | By :
                            Pine |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Code (PHP) 
 $simple_search = array( 
'https://maps.google.co.th/maps/ms?(.*?)',
 
 ที่เหลือ เหมือนเดิม ลองดูครับ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-07-13 11:47:58 | By :
                            Pine |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | pattern ที่ผมให้มันผิดครับ ผมไม่ถนัด regular expression เลย ขอค้นแป๊บ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-07-13 21:03:49 | By :
                            Pine |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | โทษครับ.. CKeditor ก็มีโหมด  ดูรหัส HTML ให้เลือกใช้นี่ครับ ไม่จำเป็นต้องไปหาเขียน Gex ไรเลยนี่นา  ใส่ Iframe อะไรก็ว่ากันไปได้นี่ครับ
 
 
 Demo = http://ckeditor.com/demo/
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-07-14 10:07:10 | By :
                            deawx |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | เอิ่ม .. เขียนวิธีใช้ให้ผู้ใช้งานไปด้วยสิคะ ทำตัวแดง ๆ หนา ๆ ไว้ ให้เตะตา 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-07-14 18:52:09 | By :
                            Th@iDev |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ได้แล้วครับ ฮ่าๆๆๆ ติดตรงเครื่องหมาย ? ใน RegEx ซะงั้น 
 Code (PHP)
 
 <?php
function bbcode_format($str) {  
	$simple_search = array(  
   '/https:\/\/maps.google.co.th\/maps\/(.*)/'
);
	$simple_replace = array(  
'<iframe width="550" height="500" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.co.th/maps/$1&output=embed"></iframe>'
);
    $str = preg_replace($simple_search, $simple_replace, $str);
    return $str;
}
$text = 'asasasasasmlkm;fldgm; ldmfg; l;jrehtl;j; lfkg https://maps.google.co.th/maps/ms?msid=212125916377612783576.0004bc39db64b7bcf8395&msa=0';
echo bbcode_format($text);
?>
 |  
              | 
 ประวัติการแก้ไข
 2012-07-14 19:03:35
 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-07-14 19:01:48 | By :
                            Pine |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 |  |