alexmadsen Posted January 21, 2007 Share Posted January 21, 2007 HI ,whenever my site users posted a text(html base without strip tags) , if html post contain a closed tags and incomplete tags ; mixed my site main html .example :posted : 11111</TR><TR><DIV id=postbody><P> </P><P>2222<BR>3333 </TR><TR> <BR>44444<BR>- <BR>-55555<BR>- 666666666666666666&nbs;pgsdg<BR>- 77777777777 ... sdgsdsdg <BR>- 88888888888888 </P></DIV>********corrected with gmail editor : 11111<table><tr><td><div><p> </p><p>22223333 </p></div></td></tr><tr><td><img> 44444- <img> <img>-55555- 666666666666666666<img>&nbs;pgsdg- 77777777777<img> ... sdgsdsdg <img>- 88888888888888 <img></td></tr></table></div>************************************how I can correct posted html to a html that is safe to my main html similar gmail? with php or javascript ?please help me ? Link to comment https://forums.phpfreaks.com/topic/35071-how-i-can-correct-posted-html-to-a-html-that-is-safe/ Share on other sites More sharing options...
ToonMariner Posted January 21, 2007 Share Posted January 21, 2007 you'll need to create some kind of regular expression similar to a html validator and extend it to add the html required to make it safe for your site. Link to comment https://forums.phpfreaks.com/topic/35071-how-i-can-correct-posted-html-to-a-html-that-is-safe/#findComment-165588 Share on other sites More sharing options...
nogray Posted January 22, 2007 Share Posted January 22, 2007 There is a very easy way to do this. Firefox and IE have this cool function that will correct any HTML code that is inserted into the page using JavaScript. They'll close all the tags and fix the HTML code without you having to do anything. Here is a basic script that will take the input from a textarea and assign it to a div. The browser will fix the HTML. Finally, get the HTML value for that div and assign it the textarea value.[code]<script language="javascript"> function correctHTML(){ txt = document.getElementById('HTML_Code').value; document.getElementById('fixing_div').innerHTML = txt; document.getElementById('HTML_Code').value = document.getElementById('fixing_div').innerHTML; }</script><textarea name="HTML_Code" id="HTML_Code"></textarea><div style="display:none;" id="fixing_div"></div><button onclick="correctHTML();">Correct HTML</button>[/code] Link to comment https://forums.phpfreaks.com/topic/35071-how-i-can-correct-posted-html-to-a-html-that-is-safe/#findComment-166495 Share on other sites More sharing options...
alexmadsen Posted January 27, 2007 Author Share Posted January 27, 2007 [quote author=nogray link=topic=123345.msg510670#msg510670 date=1169488203]There is a very easy way to do this. Firefox and IE have this cool function that will correct any HTML code that is inserted into the page using JavaScript. They'll close all the tags and fix the HTML code without you having to do anything. Here is a basic script that will take the input from a textarea and assign it to a div. The browser will fix the HTML. Finally, get the HTML value for that div and assign it the textarea value.[code]<script language="javascript"> function correctHTML(){ txt = document.getElementById('HTML_Code').value; document.getElementById('fixing_div').innerHTML = txt; document.getElementById('HTML_Code').value = document.getElementById('fixing_div').innerHTML; }</script><textarea name="HTML_Code" id="HTML_Code"></textarea><div style="display:none;" id="fixing_div"></div><button onclick="correctHTML();">Correct HTML</button>[/code][/quote]this is not work correctly in IE with </tr> or <tr> tags . Link to comment https://forums.phpfreaks.com/topic/35071-how-i-can-correct-posted-html-to-a-html-that-is-safe/#findComment-170405 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.