TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   pregreplace & minor bbcoding (http://www.talkphp.com/general/3212-pregreplace-minor-bbcoding.html)

Evulness 08-04-2008 03:18 PM

pregreplace & minor bbcoding
 
Ok, heres my deal.

Code:

echo '<tr align="center">';
foreach ($row as $key => $value) {
    if ($key == "id"){
    echo '<td bgcolor="'.$bg.'" ><a href="index.php?page=edit&id='.$value.'">'.$value.'</a></td>';
    }else{
        if ($key == "comment"){
            echo '<td bgcolor="'.$bg.'" width="25%" >'.$value.'</td>';}
                    else{echo '<td bgcolor="'.$bg.'" >'.$value.'</td>';
        }
    }
  }
    echo "</tr>";

query for above code
Quote:

sql ="SELECT id, username, email, first_name, last_name, nonprofit_date, packet1, packet2, comment
FROM users
WHERE level=1
ORDER by ".$order." ".$dir."
LIMIT ".$limit."
";
when i do this, my comment cell is a bunch of comments. each seperate comment is surrounded like bbcode [my comment1] [mycomment2]

what i need to do is take this part:
Code:

if ($key == "comment"){
            echo '<td bgcolor="'.$bg.'" width="25%" >'.$value.'</td>';}
                    else{echo '<td bgcolor="'.$bg.'" >'.$value.'</td>';
        }

and i need to parse out that indevidual if() statement, and make it parts out each [] and put it on a seperate line. i know i need to use a preg_replace. but preg_replace is so forigne to me... i can't figure out how to get it to work.

any suggestions?

Evulness 08-04-2008 03:22 PM

oh. and if i can begin each comment with an asterisk * so my $value for $comment would be something like this....

$comment = "*unpaid amount due. *need to re-send fax sheet";

sketchMedia 08-04-2008 03:32 PM

This should get you started.

p.s. im not the best at regex so im sure there is a quicker way.

PHP Code:

$string '[bold]this will be turned bold hopefully[/bold]';
echo 
preg_replace('/\[bold\](.*)\[\/bold\]/is''<b>\\1</b>'$string); 



All times are GMT. The time now is 11:47 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0