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
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Wed Feb 18, 2004 5:52 pm
I have a bbcode file (in a folder called includes) and its contents is this:
Code: Select all
<?php
function bbcode($str)
{
// Bold Text ([b]text goes here[/b])
$str = preg_replace('/([b])(.+?)([/b])/i', "<b>\2</b>",$str);
// Italic Text ([i]text goes here[/i])
$str = preg_replace('/([i])(.+?)([/i])/i', "<i>\2</i>",$str);
// Underlined Text ([u]text goes here[/u])
$str = preg_replace('/([u])(.+?)([/u])/i', "<u>\2</u>", $str);
return $str;
}
?>
How do i get it to work on a page (eg; viewtopic.php)
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Wed Feb 18, 2004 5:58 pm
include "includes/bbcode.php";
$str = "blah";
$newstr = bbcode($str);
something like that.....
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Wed Feb 18, 2004 6:02 pm
See im making a forum and i just need to enable BBCodes so how would i include that to a forum?
Code: Select all
include "includes/bbcode.php";
$str = "(ALL PAGE CONTENT)";
$newstr = bbcode($str);
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Wed Feb 18, 2004 6:13 pm
we'll you'll probably have something like this for the message:
Code: Select all
<?php
<form action=message.php method=POST><textarea name=comment></textarea><input type=submit value=Submit>
?>
on message.php have something like:
Code: Select all
<?php
include "includes/bbcode.php";
if(isset($comment)) {
$newstr = bbcode($comment);
}
?>
understand that?
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Wed Feb 18, 2004 6:21 pm
Nope not really... lol
newthread.php (Showing form section):
Code: Select all
<form action="newthreaded.php" method="post">
<?php
echo("<input type="hidden" name="forumid" value="".$_GET['forumid']."">");
?>
<center>
<table cellspacing="0" cellpadding="4" width="<? print $cnttwidth ?>%">
<tr>
<td width="100%" colspan="2" bgcolor="#<? print $tbltop ?>" align="left"><font face="<? print $font ?>" size="<? print $medtxt ?>"><b>Post A New Thread</b></font></td>
</tr>
<tr>
<td width="40%" bgcolor="#<? print $row1 ?>" align="left"><font face="<? print $font ?>" size="<? print $medtxt ?>"><b>Author Name:</b></font></td>
<td width="60%" bgcolor="#<? print $row2 ?>" align="left"><font face="<? print $font ?>" size="<? print $medtxt ?>"><input type="text" name="author" size="25"></font></td>
</tr>
<tr>
<td width="40%" bgcolor="#<? print $row1 ?>" align="left"><font face="<? print $font ?>" size="<? print $medtxt ?>"><b>Icon:</b></font></td>
<td width="60%" bgcolor="#<? print $row2 ?>" align="left"><font face="<? print $font ?>" size="<? print $smlltxt ?>">
<label for=icon0><input type=radio name=icon value="noic" checked><font face="<? print $font ?>" size="<? print $smlltxt ?>">No Icon</font></label><br>
<label for=icon1><input type=radio name=icon value="icon1"><img src="./images/icons/icon1.gif"></label>
<label for=icon2><input type=radio name=icon value="icon2"><img src="./images/icons/icon2.gif"></label>
<label for=icon3><input type=radio name=icon value="icon3"><img src="./images/icons/icon3.gif"></label>
<label for=icon4><input type=radio name=icon value="icon4"><img src="./images/icons/icon4.gif"></label>
<label for=icon5><input type=radio name=icon value="icon5"><img src="./images/icons/icon5.gif"></label>
<label for=icon6><input type=radio name=icon value="icon6"><img src="./images/icons/icon6.gif"></label>
<label for=icon7><input type=radio name=icon value="icon7"><img src="./images/icons/icon7.gif"></label><br>
<label for=icon8><input type=radio name=icon value="icon8"><img src="./images/icons/icon8.gif"></label>
<label for=icon9><input type=radio name=icon value="icon9"><img src="./images/icons/icon9.gif"></label>
<label for=icon10><input type=radio name=icon value="icon10"><img src="./images/icons/icon10.gif"></label>
<label for=icon11><input type=radio name=icon value="icon11"><img src="./images/icons/icon11.gif"></label>
<label for=icon12><input type=radio name=icon value="icon12"><img src="./images/icons/icon12.gif"></label>
<label for=icon13><input type=radio name=icon value="icon13"><img src="./images/icons/icon13.gif"></label>
<label for=icon14><input type=radio name=icon value="icon14"><img src="./images/icons/icon14.gif"></label><br>
</td>
</tr>
<tr>
<td width="40%" bgcolor="#<? print $row1 ?>" align="left"><font face="<? print $font ?>" size="<? print $medtxt ?>"><b>Title:</b></font></td>
<td width="60%" bgcolor="#<? print $row2 ?>" align="left"><font face="<? print $font ?>" size="<? print $medtxt ?>"><input type="text" name="title" size="25"></font></td>
</tr>
<tr>
<td width="40%" bgcolor="#<? print $row1 ?>" align="left"><font face="<? print $font ?>" size="<? print $medtxt ?>"><b>Post:</b></font></td>
<td width="60%" bgcolor="#<? print $row2 ?>" align="left"><font face="<? print $font ?>" size="<? print $medtxt ?>"><textarea rows="15" cols="45" name="post"></textarea></font></td>
</tr>
<tr valign="top">
<td width="100%" colspan="2" bgcolor="<? print $tbltop ?>"><center><font face="<? print $font ?>" size="<? print $smlltxt ?>">(<b>NOTE:</b> You will not be able to re-edit your post in the future.)<br><input type="submit" value="Post Thread"></font></center></td>
</tr>
</table>
</center>
</form>
newthreaded.php (Whole thing)
Code: Select all
<?
// ADD COPYRIGHT NOTICE HERE
include("header.php");
// #######################################################################################
// # Inserts Thread In 'threads' Table
// #######################################################################################
$id=$_POST['id'];
$icon=$_POST['icon'];
$forumid=$_POST['forumid'];
$title=$_POST['title'];
$author=$_POST['author'];
$post=$_POST['post'];
$sql = "INSERT INTO dfga_threads (id,icon,forumid,title,author,post,posted,replies,views) VALUES ('', '$icon', '$forumid', '$title', '$author', '$post', NOW(), 0, 0);";
$result = mysql_query($sql) or die(mysql_error());
// #######################################################################################
// # Updates Thread Count On index.php
// #######################################################################################
$forumid=$_POST['forumid'];
$sql = "UPDATE dfga_forums SET threads=threads+1 WHERE id = '$forumid'";
$result = mysql_query($sql) or die(mysql_error());
// #######################################################################################
// # Updates Post Count On index.php (Disabled)
// #######################################################################################
/*
$forumid=$_POST['forumid'];
$sql = "UPDATE dfga_forums SET posts=posts+1 WHERE id = '$forumid'";
$result = mysql_query($sql) or die(mysql_error());
*/
// #######################################################################################
// # Inserts Thread In 'posts' Table
// #######################################################################################
$id=$_POST['id'];
$title=$_POST['title'];
$author=$_POST['author'];
$post=$_POST['post'];
$threadid=$_POST['threadid'];
$sql = "INSERT INTO dfga_posts (id,title,author,post,date,threadid) VALUES ('', '$title', '$author', '$post', NOW(), '$threadid');";
$result = mysql_query($sql) or die(mysql_error());
// #######################################################################################
// # Notifies That The Post Has Been Entered
// #######################################################################################
if($result)
echo "<font face="$font" size="$medtxt">Thread Posted!<br><br><br>[ <a href="./viewforum.php?fid=$forumid">Go Back To Forum</a> ]</font>";
include("footer.php");
?>
Please Note: Me coding is very very very messy
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Wed Feb 18, 2004 6:28 pm
I dont think u coded that because what I told you is simple enought o patch into your code.
no offense.
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Wed Feb 18, 2004 6:32 pm
Its snippets from here there and everywhere and id just added a few of my own touches... so dont jump to conclusions :\
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Wed Feb 18, 2004 6:39 pm
well look at the lines in my code.... look how I passed the variable from the form.
use
Code: Select all
<form action="newthreaded.php" method="post" name=comment>
now look at the rest of my code example.. you should be able to follow it.
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Wed Feb 18, 2004 6:48 pm
So name my form... done that then... (cuz this is the confusing bit for me...)
I suppose i add
just under
. But how would i do
Code: Select all
if(isset($comment)) {
$newstr = bbcode($comment);
} ????
viewthread.php
Code: Select all
<?php include ("header.php");
echo("<a href="./newthread.php?forumid=".$_GET['fid'].""><img src="./images/newthread.gif" border="0"></a> ");
echo("<a href="./newreply.php?threadid=".$_GET['threadid']."&forumid=".$_GET['fid'].""><img src="./images/reply.gif" border="0"></a>");
?>
<table border="<? print $tblbrdwidthi ?>" bordercolor="#<? print $tblbrdcolori ?>" cellspacing="0" cellpadding="0" width="<? print $cnttwidth ?>%">
<tr>
<td width="25%" align="left" bgcolor="#<? print $tbltop ?>"><font face="<? print $font ?>" size="<? print $smlltxt ?>"> <b>Author</b></font></td>
<td width="75%" align="left" bgcolor="#<? print $tbltop ?>"><font face="<? print $font ?>" size="<? print $smlltxt ?>"> <b>Thread</b></font></td>
</tr>
<?
$query = "SELECT * FROM dfga_threads WHERE id=".$_GET['threadid']."";
$result = mysql_query($query) or die(mysql_error());
while($r=mysql_fetch_array($result))
{
$id=$r["id"];
$title=$r["title"];
$author=$r["author"];
$post=$r["post"];
$date=$r["date"];
$threadid=$r["threadid"];
echo "<tr valign="top">
<td width="25%" align="left" bgcolor="#$row1">
<font face="$font" size="$medtxt"> <b>$author</b></font><br>
<br>
<br>
<br>
<br>
<td width="75%" align="left" bgcolor="#$row2">
<font face="$font" size="$smlltxt"> <b>$title</b></font><br>
<font face="$font" size="$medtxt"> $post</font><br>
</td>
</tr>
<tr valign="center">
<td width="25%" align="left" bgcolor="#$tbltop"><font face="$font" size="$smlltxt"> $date</font></td>
<td width="75%" align="left" bgcolor="#$tbltop"><font face="$font" size="$smlltxt"> </font></td>
</tr>";
}
$query = "SELECT * FROM dfga_posts WHERE threadid=".$_GET['threadid']."";
$result = mysql_query($query) or die(mysql_error());
while($r=mysql_fetch_array($result))
{
$id=$r["id"];
$title=$r["title"];
$author=$r["author"];
$post=$r["post"];
$date=$r["date"];
$threadid=$r["threadid"];
echo "<tr valign="top">
<td width="25%" align="left" bgcolor="#$row1">
<font face="$font" size="$medtxt"> <b>$author</b></font><br>
<br>
<br>
<br>
<br>
<td width="75%" align="left" bgcolor="#$row2">
<font face="$font" size="$smlltxt"> <b>$title</b></font><br>
<font face="$font" size="$medtxt"> $post</font><br>
</td>
</tr>
<tr valign="center">
<td width="25%" align="left" bgcolor="#$tbltop"><font face="$font" size="$smlltxt"> $date</font></td>
<td width="75%" align="left" bgcolor="#$tbltop"><font face="$font" size="$smlltxt"> </font></td>
</tr>";
}
$result = "UPDATE dfga_threads SET views=views+1 WHERE id = '$threadid'";
mysql_query($result) or die(mysql_error());
?>
</table>
<?php include("footer.php");?>
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Wed Feb 18, 2004 6:57 pm
okay
let me break down the ABC's for you.. in the form (on newthread.php) your passing the form data (called $comment cause name=comment) to the page newthreaded.php...
so now on newthreaded.php:
we have the variable $comment (which is the message or post or whatver u wish to call it)..with me so far? now with the include function that is including your BBCODE(s) function from whatever page it is on, all u have to do is call the variable $comment (with the isset() function) and apply your bbcode function to it (as showed above)
Now do we have a understanding? if not, let me know what your unclear on. Adding your info to existing code can be dangerous especially if you dont know how stuff works, your just asking for head-aches n confusing.
I suggest you write your own code n that way you know how it works from head to toe, inside to out.
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Wed Feb 18, 2004 7:06 pm
I know a basic rough guide to what things do what.. anyways ISSET function... heard of one of them before.... but i totally am stumped! Why couldnt php just be include ("blah.php"); and it works straight away... but then again there will probably be no sence of adventure will there.. anyway i am stuck with this variable business "$comment"
grrr life is bad :\
Last edited by
Dale on Wed Feb 18, 2004 8:06 pm, edited 1 time in total.
mikegotnaild
Forum Contributor
Posts: 173 Joined: Sat Feb 14, 2004 5:59 pm
Post
by mikegotnaild » Wed Feb 18, 2004 7:27 pm
Dale... hes right. Im no php genius myself but thats not really that complicated.
Illusionist
Forum Regular
Posts: 903 Joined: Mon Jan 12, 2004 9:32 pm
Post
by Illusionist » Wed Feb 18, 2004 7:33 pm
the only problem i thinkt ehre is is that your \2 should be \\2
I didn't read any of the above post because it looked like yall were trying to add code or soemthing, but i try try the \2 to \\2 and see if it works!
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Wed Feb 18, 2004 8:05 pm
Illusionist wrote: the only problem i thinkt ehre is is that your \2 should be \\2
I didn't read any of the above post because it looked like yall were trying to add code or soemthing, but i try try the \2 to \\2 and see if it works!
Its not the /2's that im finding hard.. its this business about $comment and the Isset function... im still a php n00b and i just dont know where the hell i goto stick it in... knowing me its going to be in a really simple thing.. and what gets me is people say there no php genius but they know load sof things. See i started off with a small guestbook script i done with a few snippets of code (insert into database, show from database) and from that i've got help from
markl999 over in the database room with a few commands and voila i have a forum... *got im blabbering on too much :\
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Wed Feb 18, 2004 8:05 pm
Okay, you dont understand where $comment is coming from, examine this:
Code: Select all
<form action="newthreaded.php" method="post" name=comment>
name = variable name which is called comment in the above example
you can make it anything you want, i was just using comment for no special reason but to show u the code that u would need.
if u used name=msg, the variable would be $msg
That help any?