我遇到的问题是在文本区域的文本末尾插入<br>
的表单,并且会在每次提交时插入新的中断。当我再次进入编辑器时,这些中断将是可见的。我插入了以下代码,它似乎工作,<br>
s不再在编辑器中成倍增加或显示。
$x = preg_replace("/^<br(\/|)>/i","\n",$x);
$x = preg_replace("/(^)?(<br\s*\/?>\s*)+$/","\n", $x);
但是,现在它在文本末尾输入两个<br>
标记时将它放入SQL中。
我之前关于此的帖子是Here。
已修改为包含表单信息
的代码<?php
include ("main_fns.php"); // This file would include your database access and login functions, include this at the top of EVERY page, in order to carry the session between pages and access the database.
open_db(); // Open a database connection
$page_file = "sample.php"; // the file name of this page
$page_title = "Course Admin Area"; // can be fed into the header
include ("header.php");
// Check for logged in session variable, else prompt for login.
if (!@$_SESSION["email"]) {
loginPrompt(@$_POST["email"],$_SESSION["error"]);
} else {
// PAGE CONTENT GOES HERE
function fromhtml ($x) {
$x = preg_replace("/<p>/i","\n\n",$x);
$x = preg_replace("/^<br(\/|)>/i","\n",$x);
$x = preg_replace("/<li>/i","\n<li>",$x);
$x= preg_replace("/(^)?(<br\s*\/?>\s*)+$/","\n", $x);
return $x;
}
$DBhost = "localhost";
$DBuser = "daccweb";
$DBpass = "go";
$DBName = "DACC";
mssql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
@mssql_select_db("$DBName") or die("Unable to select database $DBName");
$PHP_SELF = $_SERVER['PHP_SELF'];
$course_id = @$_GET["course"];
if ($course_id == "") {
//$sqlquery = "SELECT id,title,goals,outline,reference,DATE_FORMAT(updated, '%Y/%m/%d %H:%i:%S') as updated2 FROM courses WHERE division_id = '$division_id' ORDER BY id";
$sqlquery = "SELECT id, title, goals, outline, reference, deliverymode, updated2 = CONVERT(VARCHAR(19), updated, 120)
FROM courses WHERE division_id = '$division_id' ORDER by id";
$result = mssql_query($sqlquery);
$number = mssql_num_rows($result);
if ($number == 0) {
print "<html><body>";
print "No courses exist for division $division_id.";
print "</body></html>";
exit;
}
print "<b>Course list - division $division_id</b><p>\n";
print "Select a course ID to edit course information.<p>\n";
print "<table border=1 id=\"content_table\"><tr><th>ID</th><th>Title</th><th>Status</th><th>Last modified</th></tr>\n";
$i = 0;
while ($number > $i) {
$course_id = mssql_result($result,$i,"id");
$reference = mssql_result($result,$i,"reference");
$updated = mssql_result($result,$i,"updated2");
print "<tr><td>";
if ($reference == "") {
print "<a href=$PHP_SELF?division=$division_id&course=$course_id>$course_id</a>";
} else {
print "$course_id";
}
print "</td><td>";
print mssql_result($result,$i,"title");
print "</td><td>";
if ($reference == "") {
if ( (mssql_result($result,$i,"goals")=="") and (mssql_result($result,$i,"outline")=="") ) {
print "<b>No syllabus, or incomplete</b></td>";
}
} else {
print "Based on $reference";
}
print "</td><td>$updated</td>\n";
print "</tr>\n";
$i++;
}
print "</table>";
exit;
}
$sqlquery = "SELECT * FROM courses WHERE id = '$course_id'";
$result = mssql_query($sqlquery);
$number = mssql_num_rows($result);
if ($number == 0) {
print "<html><body>";
print "No course with the ID \"$course_id\" exists in the course database.";
print "</body></html>";
exit;
}
$i = 0;
$title = fromhtml(mssql_result($result,$i,"title"));
$iai = fromhtml(mssql_result($result,$i,"iai"));
$deliverymode = fromhtml(mssql_result($result,$i,"deliverymode"));
$hours = fromhtml(mssql_result($result,$i,"hours"));
$type = fromhtml(mssql_result($result,$i,"type"));
$description = fromhtml(mssql_result($result,$i,"description"));
$semester = fromhtml(mssql_result($result,$i,"semester"));
$prerequisites =fromhtml(mssql_result($result,$i,"prerequisites"));
$notes = fromhtml(mssql_result($result,$i,"notes"));
$goals = fromhtml(mssql_result($result,$i,"goals"));
$outline = fromhtml(mssql_result($result,$i,"outline"));
$materials = fromhtml(mssql_result($result,$i,"materials"));
$evaluation = fromhtml(mssql_result($result,$i,"evaluation"));
$bibliography = fromhtml(mssql_result($result,$i,"bibliography"));
$revised = mssql_result($result,$i,"revised");
print "<html><head><title>DACC Course Syllabus - $course_id</title>";
print "<script language=\"JavaScript\" type=\"text/javascript\" src=\"/rte/richtext2.js\"></script>";
?>
<script language="JavaScript" type="text/javascript">
<!--
initRTE("/rte/images/", "/rte/", "");
//-->
function submitForm() {
updateRTEs();
document.edit-course.submit();
return false;
}
</script>
<?php
print "</head><body>\n";
print "<a href=/courses/$division_id>Back to the $division_id course list</a>";