จากที่ลองวิธีนี้eange08 เขียน: ↑30/09/2022 2:21 pm ไปเจออีก function หนึ่งของ phpBB มาค่ะ ตัด bbcode ออกได้ เป็นใน phpBB3.3 จะไม่ return ค่าออกมา เอาในฟังกชั่นมาใช้เองได้ค่ะโค้ด: เลือกทั้งหมด
strip_bbcode(&$text, $uid = '') //$text = ข้อความที่เป็น bbcode //$uid = ส่ง bbcode_uid ของ post นั้นจะมีใน table phpbb_posts
ก่อนใช้โค้ด: เลือกทั้งหมด
public function hiddenBBCode($text, $uid) { global $phpbb_root_path,$phpbb_container; if (preg_match('#^<[rt][ >]#', $text)) { $text = utf8_htmlspecialchars($phpbb_container->get('text_formatter.utils')->clean_formatting($text)); } else { if (!$uid) { $uid = '[0-9a-z]{5,}'; } $text = preg_replace("#\[\/?[a-z0-9\*\+\-]+(?:=(?:".*"|[^\]]*))?(?::[a-z])?(\:$uid)\]#", ' ', $text); $match = get_preg_expression('bbcode_htm'); $replace = array('\1', '\1', '\2', '\1', '', ''); $text = preg_replace($match, $replace, $text); } return $text; }
Selection_999(152).png
หลังใช้
Selection_999(153).png
ตัวอย่าง code function
โค้ด: เลือกทั้งหมด
public function hiddenBBCode($text, $uid)
{
global $phpbb_container;
if (preg_match('#^<[rt][ >]#', $text)) {
$text = utf8_htmlspecialchars($phpbb_container->get('text_formatter.utils')->clean_formatting($text));
} else {
if (!$uid) {
$uid = '[0-9a-z]{5,}';
}
$text = preg_replace("#\[\/?[a-z0-9\*\+\-]+(?:=(?:".*"|[^\]]*))?(?::[a-z])?(\:$uid)\]#", ' ', $text);
$match = get_preg_expression('bbcode_htm');
$replace = '';
$text = preg_replace($match, $replace, $text);
}
return $text;
}
โค้ด: เลือกทั้งหมด
$this->hiddenBBCode($row['post_text'], $row['bbcode_uid'])
โค้ด: เลือกทั้งหมด
Solved asd [2022-09][00172]Solved asd [2022-09][00172] img_avatar2.png [attachment=0]img_avatar3.png[/attachment] img_avatar3.png
โค้ด: เลือกทั้งหมด
[b]Solved asd [2022-09][00172]Solved asd [2022-09][00172][/b]
[attachment=0]img_avatar2.png[/attachment]
[code]
[attachment=0]img_avatar3.png[/attachment]
[code]// ถ้าไปเป็น test จริงต้องใส่ / ด้วย
[attachment=0]img_avatar3.png[/attachment]
ได้ข้อมูลตามความต้องการครับ