A-AA+then

preg_replace

5,196

ใครรู้บ้างว่าความหมายของสัญลักษณ์ต่างๆคืออะไร แนะนำที มีเยอะดีจริงๆ

ดูเฉพาะส่วน preg_replace

ไม่รู้ พวกนี้เอาเอามาจากไหนมารวมกัน  (.*?)   #si  #usi  ([^\s]*) และอีกเยอะมากมาย มันเรียนพวกนี้ว่าอะไรหรอ

 <?php// File: $Id$ /** * pn_bbdecode/pn_bbencode functions: * Rewritten - Nathan Codding - Aug 24, 2000 * Using Perl-Compatible regexps now. Won't kill special chars * outside of a ... block now, and all BBCode tags * are implemented. * Note: the "i" matching switch is used, so BBCode tags are * case-insensitive. */ function pn_bbdecode($message) { // Undo  $message = preg_replace("#<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD>Code:<HR></TD></TR><TR><TD><PRE>(.*?)</PRE></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode End -->#s", "[code]", $message); // Undo 
อ้างจากคำถาม $message = preg_replace("#<!-- BBCode Quote Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD>Quote:<HR></TD></TR><TR><TD><BLOCKQUOTE>(.*?)</BLOCKQUOTE></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode Quote End -->#s", "
อ้างจากคำถาม
", $message); // Undo and $message = preg_replace("#<!-- BBCode Start --><B>(.*?)</B><!-- BBCode End -->#s", "", $message); $message = preg_replace("#<!-- BBCode Start --><I>(.*?)</I><!-- BBCode End -->#s", "", $message); // Undo " target="_blank" rel="nofollow"> (both forms) $message = preg_replace("#<!-- BBCode Start --><A HREF=\"http://(.*?)\" TARGET=\"_blank\">(.*?)</A><!-- BBCode End -->#s", "[url=]", $message); // Undo [email] $message = preg_replace("#<!-- BBCode Start --><A HREF=\"mailto:(.*?)\">(.*?)</A><!-- BBCode End -->#s", "[email][/email]", $message); // Undo
http://" alt="">
", $message); //$message = preg_replace("#<!-- BBCode Start --><IMG SRC=\"(.*?)\"><!-- BBCode End -->#s", "
", $message); // Undo lists (unordered/ordered) // unordered list code.. $matchCount = preg_match_all("#<!-- BBCode ulist Start --><UL>(.*?)</UL><!-- BBCode ulist End -->#s", $message, $matches); for ($i = 0; $i < $matchCount; $i++) { $currMatchTextBefore = preg_quote($matches[1][$i]); $currMatchTextAfter = preg_replace("#<LI>#s", "[*]", $matches[1][$i]); $message = preg_replace("#<!-- BBCode ulist Start --><UL>$currMatchTextBefore</UL><!-- BBCode ulist End -->#s", "[list]" . $currMatchTextAfter . "[/list]", $message); } // ordered list code.. $matchCount = preg_match_all("#<!-- BBCode olist Start --><OL TYPE=([A1])>(.*?)</OL><!-- BBCode olist End -->#si", $message, $matches); for ($i = 0; $i < $matchCount; $i++) { $currMatchTextBefore = preg_quote($matches[2][$i]); $currMatchTextAfter = preg_replace("#<LI>#s", "[*]", $matches[2][$i]); $message = preg_replace("#<!-- BBCode olist Start --><OL TYPE=([A1])>$currMatchTextBefore</OL><!-- BBCode olist End -->#si", "[list=]" . $currMatchTextAfter . "[/list]", $message); } return($message); } function pn_bbencode($message) { // and for posting code (HTML, PHP, C etc etc) in your posts. $matchCount = preg_match_all("#\[code\](.*?)\[/code\]#si", $message, $matches); for ($i = 0; $i < $matchCount; $i++) { $currMatchTextBefore = preg_quote($matches[1][$i]); $currMatchTextAfter = htmlspecialchars($matches[1][$i]); $message = preg_replace("#\[code\]$currMatchTextBefore\[/code\]#si", "<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD>Code:<HR></TD></TR><TR><TD><PRE>$currMatchTextAfter</PRE></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode End -->", $message); } //
อ้างจากคำถาม and
for posting replies with quote, or just for quoting stuff. $message = preg_replace("#\[quote\](.*?)\
#si", "<!-- BBCode Quote Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD>Quote:<HR></TD></TR><TR><TD><BLOCKQUOTE></BLOCKQUOTE></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode Quote End -->", $message); // and for bolding text. $message = preg_replace("#\[b\](.*?)\[/b\]#si", "<!-- BBCode Start --><B></B><!-- BBCode End -->", $message); // and for italicizing text. $message = preg_replace("#\[i\](.*?)\[/i\]#si", "<!-- BBCode Start --><I></I><!-- BBCode End -->", $message); // www.phpbb.com code.. $message = preg_replace("#\[url\](http://)?(.*?)\[/url\]#si", "<!-- BBCode Start --><A HREF=\"http://\" TARGET=\"_blank\"></A><!-- BBCode End -->", $message); // [url=www.phpbb.com]phpBB code.. $message = preg_replace("#\[url=(http://)?(.*?)\](.*?)\[/url\]#si", "<!-- BBCode Start --><A HREF=\"http://\" TARGET=\"_blank\"></A><!-- BBCode End -->", $message); // [email]user@domain.tld[/email] code.. $message = preg_replace("#\[email\](.*?)\[/email\]#si", "<!-- BBCode Start --><A HREF=\"mailto:\"></A><!-- BBCode End -->", $message); //
code.. $message = preg_replace("#\[img\](http://)?(.*?)\[/img\]#si", "<!-- BBCode Start --><IMG SRC=\"http://\"><!-- BBCode End -->", $message); // $message = preg_replace("#\[img\](.*?)\[/img\]#si", "<!-- BBCode Start --><IMG SRC=\"\"><!-- BBCode End -->", $message); // unordered list code.. $matchCount = preg_match_all("#\[list\](.*?)\[/list\]#si", $message, $matches); for ($i = 0; $i < $matchCount; $i++) { $currMatchTextBefore = preg_quote($matches[1][$i]); $currMatchTextAfter = preg_replace("#\[\*\]#si", "<LI>", $matches[1][$i]); $message = preg_replace("#\[list\]$currMatchTextBefore\[/list\]#si", "<!-- BBCode ulist Start --><UL>$currMatchTextAfter</UL><!-- BBCode ulist End -->", $message); } // ordered list code.. $matchCount = preg_match_all("#\[list=([a1])\](.*?)\[/list\]#si", $message, $matches); for ($i = 0; $i < $matchCount; $i++) { $currMatchTextBefore = preg_quote($matches[2][$i]); $currMatchTextAfter = preg_replace("#\[\*\]#si", "<LI>", $matches[2][$i]); $message = preg_replace("#\[list=([a1])\]$currMatchTextBefore\[/list\]#si", "<!-- BBCode olist Start --><OL TYPE=>$currMatchTextAfter</OL><!-- BBCode olist End -->", $message); } return($message); } ?>

3 ความคิดเห็น

มันต้องมีเว็บที่บอกรายละเอียดบ้าง แต่หาอย่างไงก็ไม่เจอ อาจไม่รู้ว่าเขาเรียนกันว่าอะไร

1

เรื่องยาวเลยครับ
ลองค้นหา คำว่า regular expression บนเว็บดูครับ มีหลายบทความ 
2

3
^