Its past 2AM here and I need some expert help!
Basically I'm putting together a site that the customer will be able to edit on the web themselves using a RichText editor (so they won't have to code any html).
I've been through 5 or so different rich text editors/applets and finally found the one I want. The problem is that it is called with javascript and when I try to push my HTML from the MySQL database into the javascript code there are errors (because of quotes, apostrophes, line breaks, that javascript doesn't like).
My question is this: how do I put a \ in front of the problematic characters of some HTML that I have queried into a variable in PHP?
Here is what I have:
PHP Code:
<?
$page=$_GET['page'];
include("dbinfo.inc.php");
mysql_connect("localhost",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM $page";
$result=mysql_query($query);
mysql_close();
$html=mysql_result($result,0,"HTML");
?>
<center><font size=5 face="Arial, Helvetica, sans-serif" color=black>Edit HTML</font></center>
<br><br>
<center>
<form action="updated.php" method="post">
<input type="hidden" name="page" value="<? echo $page; ?>">
HTML for <? echo $page; ?>:<br>
<SCRIPT LANGUAGE="javascript" SRC="../inc/HTMLRichTextArea.js"></SCRIPT>
<SCRIPT LANGUAGE="javascript" SRC="../inc/HTMLRichTextAreaFactorySettings.js"></SCRIPT>
<SCRIPT LANGUAGE="javascript">
<!--
var strDefaultHTML = "<? echo $html; ?>";
new HTMLRichTextArea("ud_html", 80, 200, strDefaultHTML).Draw();
//-->
</SCRIPT>
<center>
<br>
<input type="Submit" value="Update">
<input type="button" value="Cancel" OnClick="location.href='index.php?page=<? echo $page; ?>'">
</center>
</form>
The problem is occuring on this line:
var strDefaultHTML = "<? echo $html; ?>";
$html is the variable that contains raw html code that I need to fix by inserting the \'s.
I know the rest of the code works because I initially coded the page using a standard <textarea> tag, and it worked fine.
|