anna_eden
01-23-2009, 11:10 PM
Hello,
I am facing a problem in my php page.The page has a editor(we use fck editor) where user can enter any thing.He can enter html or text there. when the user clicks the update button,we use Ajax to save the data in the DB.We encode the data using js escape function.The data is send using xmlhttp req as follows
request.onreadystatechange=handleResponse_page;
request.open(reqType,url,isAsynch);
request.setRequestHeader("Content-length", string.length);
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
request.send(string);
request is an XMLHTTP object,string is the string with the escaped content.
The data get save din the db with some <p> tags attached to it.
for instance
"<p><img class="" alt="" src="http://www.cpk.com/images/template/main-logo.gif" /></p>"
The specific problem I am facing is when i read it back from the database to display it on another page.Suppose user copy pasted the page source of a page and it had some broken tags(like tags having new line b/n < and >).
Consider following ex.
<html>
<body>
<h4>Cell backgrounds:</h4>
<table border="1">
<tr>
<td bgcolor="red"
>First</td>
<td>Row</td>
</tr>
</table>
</body>
</html>
The <td bgcolor="red"
> is broken into two lines this data will be saved in the DB like below to preserve the paragraph formatting
<p><html><br />
<body><br />
<br />
<h4>Cell backgrounds:</h4> <br />
<table border="1"><br />
<tr><br />
<td bgcolor="red"</p>
<p> </p>
<p>>First</td><br />
<td>Row</td><br />
</tr> <br />
<br />
</table><br />
<br />
</body><br />
</html></p>
SO when I read back the html ,the </p><p> tags inside the <td> tag malformed the html and page wont be displayed properly.To get rid of that I took the following approach in the php page where i print the data
html_entity_decode(strip_tags(<databasevalue>));
this solved the problem with html,but with this i loose the formatting if it is a plain text which is stored in the DB.
It would be great if someone out there can give me a solution for this.
Thanks in advance,
I am facing a problem in my php page.The page has a editor(we use fck editor) where user can enter any thing.He can enter html or text there. when the user clicks the update button,we use Ajax to save the data in the DB.We encode the data using js escape function.The data is send using xmlhttp req as follows
request.onreadystatechange=handleResponse_page;
request.open(reqType,url,isAsynch);
request.setRequestHeader("Content-length", string.length);
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
request.send(string);
request is an XMLHTTP object,string is the string with the escaped content.
The data get save din the db with some <p> tags attached to it.
for instance
"<p><img class="" alt="" src="http://www.cpk.com/images/template/main-logo.gif" /></p>"
The specific problem I am facing is when i read it back from the database to display it on another page.Suppose user copy pasted the page source of a page and it had some broken tags(like tags having new line b/n < and >).
Consider following ex.
<html>
<body>
<h4>Cell backgrounds:</h4>
<table border="1">
<tr>
<td bgcolor="red"
>First</td>
<td>Row</td>
</tr>
</table>
</body>
</html>
The <td bgcolor="red"
> is broken into two lines this data will be saved in the DB like below to preserve the paragraph formatting
<p><html><br />
<body><br />
<br />
<h4>Cell backgrounds:</h4> <br />
<table border="1"><br />
<tr><br />
<td bgcolor="red"</p>
<p> </p>
<p>>First</td><br />
<td>Row</td><br />
</tr> <br />
<br />
</table><br />
<br />
</body><br />
</html></p>
SO when I read back the html ,the </p><p> tags inside the <td> tag malformed the html and page wont be displayed properly.To get rid of that I took the following approach in the php page where i print the data
html_entity_decode(strip_tags(<databasevalue>));
this solved the problem with html,but with this i loose the formatting if it is a plain text which is stored in the DB.
It would be great if someone out there can give me a solution for this.
Thanks in advance,