Kullanışlı bir BBcode class projelerinizde kullanabilirsiniz.
[cc lang="php"]
class bbcode
{
// Send all text to be parsed here!
function coverpass($text)
{
// Checks if there are any BBCode Tags
$istag = strrpos($text, "]");
if($istag == 0)
return $text; // Nope, return the text
else
return $this->parsetags($text); // Yup, Parse Them
}
function parsetags($text)
{
// This is used in some blogging applications, can be uncommented for that application
//$text = str_replace("[more]", "Continued...", $text);
// Lets do some generic checks
$text = preg_replace("(\[b\](.+?)\[\/b\])is", '$1', $text); // Bold
$text = preg_replace("(\[i\](.+?)\[\/i\])is", '$1', $text); // Italics
$text = preg_replace("(\[u\](.+?)\[\/u\])is", '$1', $text); // Underline
$text = preg_replace("(\[s\](.+?)\[\/s\])is", '$1', $text); // Strike through
$text = preg_replace("(\[o\](.+?)\[\/o\])is", '$1', $text); // Overline
$text = preg_replace("(\[font=(.+?)\](.+?)\[\/font\])", '$2', $text); // Font
$text = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is", '$2', $text); // Color
$text = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is", '$2', $text); // Font-Size
$text = preg_replace("/\[list\](.+?)\[\/list\]/is", '
- $1
$text = str_replace("[*]", "
// Code and Quote Tags
$text = preg_replace("(\[code\](.+?)\[\/code\])is", '$1', $text); // Code
$text = preg_replace("(\[quote\](.+?)\[\/quote\])is", '$1', $text); // Quote
// Allow images?
if(isset($GLOBALS['allow_image']) && ($GLOBALS['allow_image'] == 1))
{
$text = preg_replace("/\[img\](.+?)\[\/img\]/", '', $text); // Image
$text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '', $text); //Image with width and height
}
else
{
$text = preg_replace("/\[img\](.+?)\[\/img\]/", 'Admin has not allowed images!', $text); // Image
$text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", 'Admin has not allowed images!', $text); //Image with width and height
}
// Allowed Links?
if(isset($GLOBALS['allow_href']) && ($GLOBALS['allow_href'] == 1))
{
$text = preg_replace("/\[url\]([ a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\']*)\[\/url\]/", '$1', $text); // Url
$text = preg_replace("(\[url\=([ a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\']*)\](.+?)\[/url\])", '$2', $text); // Url with text
}
else
{
$text = preg_replace("/\[url\]([ a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\']*)\[\/url\]/", 'Admin has not allowed links!', $text); // Url
$text = preg_replace("(\[url\=([ a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\']*)\](.+?)\[/url\])", 'Admin has not allowed links!', $text); // Url with text
}
// Allow EMail Links?
if(isset($GLOBALS['allow_mail']) && ($GLOBALS['allow_mail'] == 1))
{
$text = preg_replace("(\[mail\]([ a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\' a-zA-Z0-9\.@]*)\[/mail\])", '$1', $text); // Mail
$text = preg_replace("/\[mail\=([ a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\' a-zA-Z0-9\.@]*)\](.+?)\[\/mail\]/", '$2', $text); // Mail with text
}
else
{
$text = preg_replace("(\[mail\]([ a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\' a-zA-Z0-9\.@]*)\[/mail\])", 'Admin has not allowed mail links!', $text); // Mail
$text = preg_replace("/\[mail\=([ a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\' a-zA-Z0-9\.@]*)\](.+?)\[\/mail\]/", 'Admin has not allowed mail links!', $text); // Mail with text
}
// Allow Videos?
if(isset($GLOBALS['allow_videos']) && ($GLOBALS['allow_videos'] == 1))
{
$youtube_replacement = '';
$text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", $youtube_replacement, $text); // YouTube
$youtube_replacement = '';
$text = preg_replace("/\[youtube=([0-9]*)x([0-9]*)\](.+?)\[\/youtube\]/", $youtube_replacement, $text); // YouTube with width/height
$googlevid_replacement = '
Bu İçeriğe Ulaşmak için Arama Motorlarında Şu Şekilde Arama Yapıyorlar :
PHP BBCode Class,
eyvallah hocam paylaşımın için teşekkürler. kullanım örneği gösterebilir misin acaba ?
YanıtlaSilHocam kullanımı hakkında biraz bilgilendirseniz. Anladığım kadarı ile BBcode'lu text verisini alıyor ve html'e çeviriyor.
YanıtlaSil[...] [...]
YanıtlaSilAwesome article post.Thanks Again. Much obliged. edddgfdbfedc
YanıtlaSilI do agree with all the ideas you have introduced for your post. They are really convincing and can certainly work. Still, the posts are very brief for newbies. May you please extend them a bit from subsequent time? Thank you for the post. dadbefafkdek
YanıtlaSil