0

[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.

4
Contributors
3
Replies
20
Views
4 Years
Discussion Span
Last Post by diafol
0

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 ^_^

0

Try this:

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

Edited by pritaeas

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.