PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Gappa
Forum Contributor
Posts: 119 Joined: Fri May 23, 2003 10:02 am
Post
by Gappa » Wed Jun 04, 2003 9:18 am
Firstly the code...
Code: Select all
<?php
$db = mysql_connect("localhost", "Gappa", " ");
mysql_select_db("Gappa",$db);
$query = 'SELECT topic_title, topic_id, FROM_UNIXTIME(topic_time,"%W the %D %M @ %r") AS Topic_Date, post_text, username FROM phpbb_topics RIGHT JOIN phpbb_posts_text ON topic_first_post_id=post_id RIGHT JOIN phpbb_users ON topic_poster=user_id WHERE forum_id=6 ORDER BY topic_time DESC';
$result = mysql_query($query, $db) or die ($query .': '.mysql_error());
while($row = mysql_fetch_assoc($result))
{
echo "<b><FONT FACE=Arial SIZE=-1 COLOR=#FF9900>";
echo "$row[topic_title]:</FONT></b><br/>";
echo "<FONT FACE=Arail SIZE=-2 COLOR=#999999>posted by: <b>$row[username]</b>";
echo " on: ";
echo "$row[Topic_Date]</FONT><br/><hr><br/>";
echo "<FONT FACE=Arail SIZE=-1 COLOR=#FFFFFF> $row[post_text]</FONT>";
echo "<br/><br/>";
echo "<FONT FACE=Arial SIZE=-2>";
echo "<a href="http://www.hostultra.com/~Gappa/phpBB2/viewtopic.php?t=$row[topic_id]"><b><FONT COLOR=#FF9900>Read comments</FONT></b></a></FONT>";
echo "<br/><br/><br/>";
}
?>
Ok how do I go about having the post_text use BBCode, and is this possible?
patrikG
DevNet Master
Posts: 4235 Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK
Post
by patrikG » Wed Jun 04, 2003 9:51 am
Not a direct answer to your question, but there is a class at
php.classes.org which does just that
Gappa
Forum Contributor
Posts: 119 Joined: Fri May 23, 2003 10:02 am
Post
by Gappa » Wed Jun 04, 2003 6:53 pm
There are codes for this at Evilwalrus.com but I having trouble getting them to work... any ideas
Gappa
Forum Contributor
Posts: 119 Joined: Fri May 23, 2003 10:02 am
Post
by Gappa » Wed Jun 04, 2003 10:43 pm
damn ok.. i got no idea how to implerment that, i understand it just replaces html tags with bbcode basically but getting it to work is another thing.
I want to have it so it changes the post_text (which is pulled from my database). I'm guessing i need to send it out as a text string to another php file which converts html tags to bbcode then sends it back and outputs it to the original php file. (which is basically a database driven news script)
Any ideas here... ?
McGruff
DevNet Master
Posts: 2893 Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland
Post
by McGruff » Wed Jun 04, 2003 11:41 pm
$search = array(.. BBtags ..);
$replace = array(.. html tags ..);
str_replace($search, $replace, $text);
..but I must have a look at these classes one day to see what I'm missing.
Gappa
Forum Contributor
Posts: 119 Joined: Fri May 23, 2003 10:02 am
Post
by Gappa » Thu Jun 05, 2003 4:03 am
Not sure who your code works McGruff.... wont that effect my entire file, rather than just one field? (I might very well be mistaken hehe, coz I dont know a hell of a lot).
Any way whould this work?
Not sure I got all the stuff right yet.. just for bold at the mo...
Code: Select all
<?php
$message = $row['post_text'];
// ubb codes
$message = preg_replace('/\[b\](.*?)\[\/b\]/is', '<b>$1</b>', $message);
// etc.
echo $message;
?>
Gappa
Forum Contributor
Posts: 119 Joined: Fri May 23, 2003 10:02 am
Post
by Gappa » Thu Jun 05, 2003 6:55 am
Just to add the above code makes the post_text display as nothing....
Code: Select all
<?php
$db = mysql_connect("localhost", "Gappa", " ");
mysql_select_db("Gappa",$db);
$query = 'SELECT topic_title, topic_id, FROM_UNIXTIME(topic_time,"%W the %D %M @ %r") AS Topic_Date, post_text, username FROM phpbb_topics RIGHT JOIN phpbb_posts_text ON topic_first_post_id=post_id RIGHT JOIN phpbb_users ON topic_poster=user_id WHERE forum_id=6 ORDER BY topic_time DESC';
$result = mysql_query($query, $db) or die ($query .': '.mysql_error());
$message = $row['post_text'];
// ubb codes
$message = preg_replace('/\[b\](.*?)\[\/b\]/is', '<b>$1</b>', $message);
// etc.
while($row = mysql_fetch_assoc($result))
{
echo "<b><FONT FACE=Arial SIZE=-1 COLOR=#FF9900>";
echo "$row[topic_title]:</FONT></b><br/>";
echo "<FONT FACE=Arail SIZE=-2 COLOR=#999999>posted by: <b>$row[username]</b>";
echo " on: ";
echo "$row[Topic_Date]</FONT><br/><hr><br/>";
echo "<FONT FACE=Arail SIZE=-1 COLOR=#FFFFFF> $message</FONT>";
echo "<br/><br/>";
echo "<FONT FACE=Arial SIZE=-2>";
echo "<a href="http://www.hostultra.com/~Gappa/phpBB2/viewtopic.php?t=$row[topic_id]"><b><FONT COLOR=#FF9900>Read comments</FONT></b></a></FONT>";
echo "<br/><br/><br/>";
}
?>
Is what the code looks like with the added addition of BBCode (bold) ... this doesnt work! bah...
?>
McGruff
DevNet Master
Posts: 2893 Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland
Post
by McGruff » Thu Jun 05, 2003 9:24 pm
[quote="Gappa"]Not sure who your code works McGruff.... [quote]
Code: Select all
<?php
$BBcode_search = array('[ b ]', '[ /b ]', '[ i ]', '[ /i ]', '[pre]', '[/pre]', '[shout]', '[/shout]', '[br]');
$BBcode_replace = array('<b>', '</b>', '<i>', '</i>', '<pre>', '</pre>', '<span class="shout">', '</span>', '<br> <br>');
?>
This example assumes an external stylesheet - and some spaces added to search values so as not to mess with this boards BB.
str_replace is case sensitive though - one advantage of preg'ing is that bot [ b ] and [ B ] are replaced.
Last edited by
McGruff on Thu Aug 11, 2005 6:55 am, edited 1 time in total.
Gappa
Forum Contributor
Posts: 119 Joined: Fri May 23, 2003 10:02 am
Post
by Gappa » Mon Jun 23, 2003 9:38 am
Hmm where would i place that code McGruff or any one else? just before the while statement?
Code: Select all
$BBcode_search = array('[ b ]', '[ /b ]', '[ i ]', '[ /i ]', '[pre]', '[/pre]', '[shout]', '[/shout]', '[br]');
$BBcode_replace = array('<b>', '</b>', '<i>', '</i>', '<pre>', '</pre>', '<span class="shout">', '</span>', '<br> <br>');
while($row = mysql_fetch_assoc($result))
... ?
But im guessing this will apply it to my entire query i just want it to target post_text
m3rajk
DevNet Resident
Posts: 1191 Joined: Mon Jun 02, 2003 3:37 pm
Post
by m3rajk » Mon Jun 23, 2003 11:12 am
damn. that's right. i need to add to my sign up and remove html ...umm... in a text area that potentially has both _ and . how does one deal with this... what does the html do to it on submission????
is the htmlspecialcharaters() like perl's chomp? or do i have to call it $veriable=htmlspecialcharacters($variable); ?
Gappa
Forum Contributor
Posts: 119 Joined: Fri May 23, 2003 10:02 am
Post
by Gappa » Mon Jun 23, 2003 11:18 am
No idea on submission, my drawing from text that already has bbcode innit so i have implement it unless i wanna have bbcode tags just hangin around...
any wya im getting this problem, for example
my italics tag isnt appearing like [/ i ] but rather .[/i:db6731649a]
what the heck :S
Gappa
Forum Contributor
Posts: 119 Joined: Fri May 23, 2003 10:02 am
Post
by Gappa » Tue Jun 24, 2003 2:40 am
No ideas any one??
Do i need to make is so it kinda disregards part of the text like the ":db6731649a" bit out of [/i:db6731649a] ??
Gappa
Forum Contributor
Posts: 119 Joined: Fri May 23, 2003 10:02 am
Post
by Gappa » Tue Jun 24, 2003 6:48 am
*sigh*
something like what i had before...
seems kinda complexe for something so simple.... ('/\[b\](.*?)\[\/b\]/is', '<b>$1</b>' dont think wreally works either, im lost...
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Jun 24, 2003 9:54 am
you might
borrow code from phpBB (this also includes the smilies-configuration)
Code: Select all
<?php
define('IN_PHPBB', true);
/**
TODO: set $phpbb_root_path
*/
$phpbb_root_path = 'phpBB2/';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
/**
might be you have to change this depending on your config-data
if you see the smilie image filenames instead of the images...
*/
$board_config['smilies_path'] = $phpbb_root_path . $board_config['smilies_path'];
$forumId = 6;
$query = 'SELECT topic_title, topic_id, FROM_UNIXTIME(topic_time,"%W the %D %M @ %r") AS Topic_Date, post_text, bbcode_uid, username FROM phpbb_topics RIGHT JOIN phpbb_posts_text ON topic_first_post_id=post_id JOIN phpbb_users WHERE forum_id='.$forumId.' AND topic_poster=user_id ORDER BY topic_time DESC';
$result = $db->sql_query($query);
?>
<html>
<head>
<style tye="text/css">
body { background-color: #333333; }
</style>
</head>
<body>
<?php
while($row = $db->sql_fetchrow($result))
{
// this field is in <prefix_>posts, I'm skipping it for now and enable all smilies
$row['enable_smilies'] = true;
// enable_bbcode (always true) and enable_html (always false) are ignored as well
$row['post_text'] = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $row['post_text']);
if ( isset($row['bbcode_uid']) && $row['bbcode_uid'] != '' )
$row['post_text'] = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($row['post_text'], $row['bbcode_uid']) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $row['post_text']);
if ($row['enable_smilies'])
$row['post_text'] = smilies_pass($row['post_text']);
?>
<b>
<FONT FACE="Arial" SIZE="-1" COLOR="#FF9900">
<?php echo $row['topic_title']; ?>
</FONT>
</b>
<br />
<FONT FACE="Arial" SIZE="-2" COLOR="#999999">
posted by: <b><?php echo $row['username']; ?></b>
on: <?php echo $row['Topic_Date']; ?>
</FONT>
<br /><hr /><br />
<FONT FACE="Arial" SIZE="-1" COLOR="#FFFFFF"><?php echo $row['post_text']; ?></FONT>
<br /><br />
<FONT FACE="Arial" SIZE="-2">
<a href="http://www.hostultra.com/~Gappa/phpBB2/viewtopic.php?t=<?php echo $row['topic_id']; ?>">
<b><FONT COLOR="#FF9900">Read comments</FONT></b>
</a>
</FONT>
<br /><br /><br />
<?php
}
?>
</body>
</html>