 |
ทำตัวยก และ ตัวห้อย ใน ckeditor ไม่ได้รบกวนด้วยครับ |
|
 |
|
|
 |
 |
|
ผมได้ทำฟอร์มรับข้อมูลด้วย ckeditor ลง mysql แต่พอจะบันทึกในรูปแบบตัวยกกำลัง หรือ ตัวห้อย ตาม toolbar ที่มีก็ทำได้แต่พอไปดูใน mysql กลับบันทึกเป็นรูปแบบข้อความติดกันธรรมดา ไม่มี tag อะไรให้เห็นที่จะเอามาแปลงได้ ซึ่งตอนแปลงเพื่อแสดงผล ผมใช้ฟังก์ชั่น bbcode ในการแปลง ตามนี้ รบกวนผู้รู้ช่วยแนะนำด้วยครับ ขอบคุณครับ
Code (PHP)
// Function BBcode สำหรับแปลงข้อความให้เป็นลิ้งค์
function showBBcodes($text) {
// NOTE : I had to update this sample code with below line to prevent obvious attacks as pointed out by many users.
// Always ensure that user inputs are scanned and filtered properly.
$text = htmlspecialchars($text, ENT_QUOTES, $charset);
// BBcode array
$find = array(
'~\[b\](.*?)\[/b\]~s',
'~\[i\](.*?)\[/i\]~s',
'~\[u\](.*?)\[/u\]~s',
'~\[quote\](.*?)\[/quote\]~s',
'~\[size=(.*?)\](.*?)\[/size\]~s',
'~\[color=(.*?)\](.*?)\[/color\]~s',
'~\[url\]((?:ftp|https?)://.*?)\[/url\]~s',
'~\[img\](https?://.*?\.(?:jpg|jpeg|gif|png|bmp))\[/img\]~s'
);
// HTML tags to replace BBcode
$replace = array(
'<b>$1</b>',
'<i>$1</i>',
'<span style="text-decoration:underline;">$1</span>',
'<pre>$1</'.'pre>',
'<span style="font-size:$1px;">$2</span>',
'<span style="color:$1;">$2</span>',
'<a href="$1" target="_blank">$1</a>',
'<img src="$1" alt="" />'
);
// Replacing the BBcodes with corresponding HTML tags
return preg_replace($find,$replace,$text);
}
// End Function BBcode สำหรับแปลงข้อความให้เป็นลิ้งค์
Tag : PHP, MySQL
|
|
 |
 |
 |
 |
Date :
2021-08-16 18:26:30 |
By :
npolkhet |
View :
978 |
Reply :
13 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต้องรู้เวอร์ชัน ckeditor และ ขั้นตอนการบันทึกลง db ก่อน
เพราะถ้าไม่มีแท็ก ต้องหาวิธีใส่แท็กตอนบันทึกด้วย
|
 |
 |
 |
 |
Date :
2021-08-16 18:39:26 |
By :
TheGreatGod_of_Death |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ckeditor 4.16.1 ส่วนการบันทึกตามโค้ดนี้ครับ
Code (PHP)
$fieldset->add('ckeditor', array(
'id' => 'abstract',
'labelClass' => 'g-input icon-file',
'itemClass' => 'item',
'label' => '{LNG_abstract}',
'comment' => '{LNG_Note or additional notes}',
'rows' => 5,
'value' => isset($index->abstract) ? $index->abstract : '',
));
|
 |
 |
 |
 |
Date :
2021-08-17 10:17:22 |
By :
npolkhet |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
download
https://ckeditor.com/cke4/addon/bbcode
แล้วเพิ่มแท็กที่ต้องการ บริเวณนี้
plugin.js
var bbcodeMap = {'sup' : 'sup', 'sub' : 'sub',...},
convertMap = {'sup' : 'sup', 'sub' : 'sub', ...},
...
|
 |
 |
 |
 |
Date :
2021-08-17 12:56:26 |
By :
TheGreatGod_of_Death |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเช็คการเรียกใช้ plugin
และลองเปลี่ยนชื่อ plugin เพื่อให้มั่นใจว่า
ckeditor เรียกอันที่เราแก้ไข ไม่ใช่ไฟล์เดิม
|
 |
 |
 |
 |
Date :
2021-08-17 13:59:05 |
By :
TheGreatGod_of_Death |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เผื่อยังไม่รู้จัก หลังจากเปลี่ยนชื่อ plugin
load plugin ตามชื่อที่เปลี่ยนใหม่ด้วย
กรณี plugin อยู่ในโครงสร้างโฟลเดอร์ CKEDITOR บน server ของเรา
config.extraPlugins = 'ชื่อ plugin ที่เปลี่ยนใหม่';
กรณีโหลด external path (เมื่อใช้ CKEDITOR แบบ cdn)
// Loads a plugin from '/myplugins/sample/plugin.js'.
CKEDITOR.plugins.addExternal( 'sample', '/myplugins/sample/' );
// Loads a plugin from '/myplugins/sample/my_plugin.js'.
CKEDITOR.plugins.addExternal( 'sample', '/myplugins/sample/', 'my_plugin.js' );
// Loads a plugin from '/myplugins/sample/my_plugin.js'.
CKEDITOR.plugins.addExternal( 'sample', '/myplugins/sample/my_plugin.js', '' );
// Loads a plugin from '/myplugins/sample/my_plugin.js'.
CKEDITOR.plugins.addExternal( 'sample', '/myplugins/sample/my_plugin.js' );
สุดท้าย
Code (JavaScript)
CKEDITOR.replace('editor1', {
extraPlugins: 'ชื่อ plugin ที่เปลี่ยนใหม่'
});
|
 |
 |
 |
 |
Date :
2021-08-18 12:30:29 |
By :
TheGreatGod_of_Death |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมเจออีกปัญหาหนึ่งคือ เวลาใส่เครื่องหมาย มากกว่า หรือ น้อยกว่า มันจะกลายเป็น > หรือ < จะแก้ปัญหานี้ใน bbcode หรือ ckeditor ยังไงครับ ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2021-09-01 17:39:16 |
By :
npolkhet |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|