Forum Moderators: coopster

Message Too Old, No Replies

unexpected T CONSTANT ESCAPED STRING

help implementing bbcode

         

bysonary

1:54 pm on Jan 22, 2007 (gmt 0)

10+ Year Member



Hello, below is my code, this relates to a closed thread that is titled "Implementing BBCODE".

Basically I have the below code, it is meant to post post the form information to the database.

however i get an error

"Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in C:\www\Apache2\htdocs\newsadd.php on line 10"

<?php
include 'dbconnect.php';

function bb2html($text)
{
$trans = array("" => "<b>", "" => "</b>",
"[u]" => "<u>", "[/u]" => "</u>",
"" => "<i>", "" => "</i>",
":-)" => "<img src=\"smile.gif\" title=\"smile :-)\">"
"

" => "<table><tr><td>", "
" => "</td></tr></table>");

$translated = strtr($text, $trans);
return $translated;
}

$pattern = "/(http:\/\/[\w\.]+)/";
$replace = "<a href='$1'>$1</a>";

$title = $_POST['title'];
$news = $_POST['news'];
$title = preg_replace($pattern, $replace, $title);
$news = preg_replace($pattern, $replace, $news);

$title = bb2html($title);
$news = bb2html($news);

$title = mysql_real_escape_string($title);
$news = mysql_real_escape_string(nl2br($news));
$date = date("D d M Y, g:i a");

$sqlquery = "INSERT INTO tnews (Title, Body, Date) VALUES ('$title','$news','$date')";

header("Location: newsdisplay.php");

//print $sqlquery;
$results = mysql_query($sqlquery);

mysql_close($dbc);
?>

Can anyone help me get this to work please?

Chris

bysonary

2:08 pm on Jan 22, 2007 (gmt 0)

10+ Year Member


I got the code working its ok it posts now the only problem with it is that in the textarea when I type [b]TEST[/b] it doesnt appear as bold it appears as [ b ]TEST[/ b ] without all the spaces between the [] can anyone help? here is the code.

<?php
include 'dbconnect.php';

function bb2html($text)
{
$trans = array("[b]" => "<b>", "[/b]" => "</b>",
"[u]" => "<u>", "[/u]" => "</u>",
"[i]" => "<i>", "[/i]" => "</i>",
":-)" => "<img src=\"smile.gif\" title=\"smile :-)\">",
"[quote]" => "<table><tr><td>", "[/quote]" => "</td></tr></table>"[smilestopper]);

$translated = strtr($text, $trans);
return $translated;
}

$pattern = "/(http:\/\/[\w\.]+)/";
$replace = "<a href='$1'>$1</a>";

$title = $_POST['title'];
$news = $_POST['news'];
$title = preg_replace($pattern, $replace, $title);
$news = preg_replace($pattern, $replace, $news);

$title = bb2html($title);
$news = bb2html($news);

$title = mysql_real_escape_string($title);
$news = mysql_real_escape_string(nl2br($news));
$date = date("D d M Y, g:i a"[smilestopper]);

$sqlquery = "INSERT INTO tnews (Title, Body, Date) VALUES ('$title','$news','$date')";

header("Location: newsdisplay.php"[smilestopper]);

//print $sqlquery;
$results = mysql_query($sqlquery);

mysql_close($dbc);
?>