|
|
|
ปัญหา tag<br/> bbcode parser กับ sql ครับช่วยแนะนำหน่อยฮะ |
|
|
|
|
|
|
|
ตามรูปเลยครับ พอแสดงผล ส่วนตัวที่ผมใช้เขียนก็ ก็อบซอทช่องคอมเม้นตรงนี้เลยฮะ (เว็บนี้แหล่ะ)
อันนี้เป็นส่วนที่ผม export code ฮะ
Code (PHP)
<? include("bbc.php");?>
<? $my_string = $row["txtDescription"];
echo bbcodeParser ($my_string);?>
อันนี้ bbc.phpฮะ
Code (PHP)
<?php
function bbcodeParser($bbcode){
/*
*
* bbCode Parser
*
* Syntax: bbcodeParser(bbcode)
*/
/*
Commands include
* bold
* italics
* underline
* typewriter text
* strikethough
* images
* urls
* quotations
* code (pre)
* colour
* size
*/
/* Matching codes */
$urlmatch = "([a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+)";
/* Basically remove HTML tag's functionality */
$bbcode = htmlspecialchars($bbcode);
/* Replace "special character" with it's unicode equivilant */
$match["special"] = "/\�/s";
$replace["special"] = '�';
/* Bold text */
$match["b"] = "/\[b\](.*?)\[\/b\]/is";
$replace["b"] = "<b>$1</b>";
/* Italics */
$match["i"] = "/\[i\](.*?)\[\/i\]/is";
$replace["i"] = "<i>$1</i>";
/* Underline */
$match["u"] = "/\[u\](.*?)\[\/u\]/is";
$replace["u"] = "<span style=\"text-decoration: underline\">$1</span>";
/* Typewriter text */
$match["tt"] = "/\[tt\](.*?)\[\/tt\]/is";
$replace["tt"] = "<span style=\"font-family:monospace;\">$1</span>";
$match["ttext"] = "/\[ttext\](.*?)\[\/ttext\]/is";
$replace["ttext"] = "<span style=\"font-family:monospace;\">$1</span>";
/* Strikethrough text */
$match["s"] = "/\[s\](.*?)\[\/s\]/is";
$replace["s"] = "<span style=\"text-decoration: line-through;\">$1</span>";
/* Color (or Colour) */
$match["color"] = "/\[color=([a-zA-Z]+|#[a-fA-F0-9]{3}[a-fA-F0-9]{0,3})\](.*?)\[\/color\]/is";
$replace["color"] = "<span style=\"color: $1\">$2</span>";
$match["colour"] = "/\[colour=([a-zA-Z]+|#[a-fA-F0-9]{3}[a-fA-F0-9]{0,3})\](.*?)\[\/colour\]/is";
$replace["colour"] = $replace["color"];
/* Size */
$match["size"] = "/\[size=([0-9]+(%|px|em)?)\](.*?)\[\/size\]/is";
$replace["size"] = "<span style=\"font-size: $1;\">$3</span>";
/* Images */
$match["img"] = "/\[img\]".$urlmatch."\[\/img\]/is";
$replace["img"] = "<img src=\"$1\" />";
/* Links */
$match["url"] = "/\[url=".$urlmatch."\](.*?)\[\/url\]/is";
$replace["url"] = "<a href=\"$1\">$2</a>";
$match["surl"] = "/\[url\]".$urlmatch."\[\/url\]/is";
$replace["surl"] = "<a href=\"$1\">$1</a>";
/* Quotes */
$match["quote"] = "/\[quote\](.*?)\[\/quote\]/ism";
$replace["quote"] = "<div class=\"bbcode-quote\">�$1�</div>";
$match["quote"] = "/\[quote=(.*?)\](.*?)\[\/quote\]/ism";
$replace["quote"] = "<div class=\"bbcode-quote\"><span class=\"bbcode-quote-user\" style=\"font-weight:bold;\">$1 said:</span><br />�$2�</div>";
/* Parse */
$bbcode = preg_replace($match, $replace, $bbcode);
/* New line to <br> tag */
$bbcode=nl2br($bbcode);
/* Code blocks - Need to specially remove breaks */
function pre_special($matches)
{
$prep = preg_replace("/\<br \/\>/","",$matches[1]);
return "�<pre>$prep</pre>�";
}
$bbcode = preg_replace_callback("/\[code\](.*?)\[\/code\]/ism","pre_special",$bbcode);
/* Remove <br> tags before quotes and code blocks */
$bbcode=str_replace("�<br />","",$bbcode);
$bbcode=str_replace("�","",$bbcode); //Clean up any special characters that got misplaced...
/* Return parsed contents */
return $bbcode;
}
?>
Tag : PHP
|
|
|
|
|
|
Date :
2013-01-15 02:32:26 |
By :
slipknotbel |
View :
1090 |
Reply :
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตอนที่ insert ได้เข้าพวก function nl2br() หรือเปล่าครับ ให้ใช้เฉพาะ mysql_real_escape_string() ก็พอครับ
|
|
|
|
|
Date :
2013-01-15 09:02:20 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
สงสัยจะไม่ เดี๋ยวลองแก้ดูฮธ ขอบพระคุณฮะ
|
|
|
|
|
Date :
2013-01-15 11:33:44 |
By :
slipknotbel |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$txtDescription = nl2br($_REQUEST["txtDescription"]);
ผมใส่แล้วนา
|
|
|
|
|
Date :
2013-01-15 11:43:59 |
By :
slipknotbel |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่ต้องใช้ครับ
|
|
|
|
|
Date :
2013-01-15 11:54:52 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วครับ Br หาย ละฮะ ขอบคุณ มากครับ
|
|
|
|
|
Date :
2013-01-15 12:39:17 |
By :
slipknotbel |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|