[b]. I have searched google and everywhere before asking this question. I have a forum that the posts support php bbcodes. All basic bbcodes like [b], [i], [h1], e.t.c are working well. I used the str_replace() function for the bbcodes. Now i have a problem on how to create the [quote] bbcode . The quote bbcode tag is in the format [quote=username]. The user wil be detected in the string and used for some database queries. The problem now lies in how to get the username infront of the [quote= in the tag. I'm so so sorry this isnt well explained but i hope you guy would please understand. I'm stil a newbie here. Guys your help wil be extremely appriciated.

Hay Farouq21 ,,

you want to replace to [quote=MsF.Shawahneh] like this ?

okay take the solution :

$text = "[quote=username] hay his is quote [/quote]";//put the text here

$username='Mohammad';//get the username from the DB here

$text = str_replace("[quote=username]","[quote=".$username."]",$text);

echo $text;

this what i understand from you but if you want the value of the bbcode take this

<style>
.qoute {
background:#333;
color:#fff;
}
.qoute .qoute_user {

background:#666;
color:#fff;

}
</style>
<?php
$text = "[quote=username] hay his is quote [/quote]";//put the text here

    $username='Mohammad';//get the username from the DB here

    $text = str_replace("[quote=username]","<div class='quote'><div class='quote_user'>posted by : ".$username."</div>",$text);//replace the started []

    $text = str_replace("[/quote]","</div>",$text);//replace the end [/]


    echo $text;
    ?>

i hope i helped you ^_^

Try this:

if (preg_match('/\[quote=(.*?)\]/', $yourText, $matches)) 
{
    $username = $matches[1];
} 
Member Avatar for diafol

Slightly off-topic, but have you considered markdown (MD) as an alternative to BBCode? It's very flexible and there are a number of libs available.

This editor uses MD and IMO, is far superior to BBCode.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.