matfish Posted August 27, 2009 Share Posted August 27, 2009 Hi, I have a javascript "MS-WORD" like script to allow users to add content to a page, this then gets inserted into the database. Cut a long story short - for some reason it just won't let me validate HTML correctly therefore I just need to know: When inserting into the database I need to do a find for <img> tags only and add a slash before the closing bracket. For example find: <img src="image.jpg" border="0"> and add <img src="image" border="0" /> I do not want to do just a find and replace on all brackets as its not needed in some cases. Ideally it needs to just look at the <img> tags and add that last slash. Any ideas? Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/172100-custom-html-validation-when-inserting-using-php/ Share on other sites More sharing options...
JonnoTheDev Posted August 27, 2009 Share Posted August 27, 2009 I have a javascript "MS-WORD" like script In other words you have a HTML text editor built in Javascript such as http://www.fckeditor.net/ You really should not have to do any replacing on elements. With these text editors there are usually configuration files that set the formatting of the document. You should be able to set XHTML as the preferred standard. If not get a better editor like the one posted above. It is fully configurable. Quote Link to comment https://forums.phpfreaks.com/topic/172100-custom-html-validation-when-inserting-using-php/#findComment-907390 Share on other sites More sharing options...
matfish Posted August 27, 2009 Author Share Posted August 27, 2009 Hi,thanks for the reply. Yes I have something similar however on this project I'm going to have to leave the current one in place as it was bespoke build with Ajax and one-click editing. When we have more time I will definitely be updating to the one you mentioned - looks great! In the meantime, I just need to alter the <img> tag as mentioned previously when the html is submitted to the database. Quote Link to comment https://forums.phpfreaks.com/topic/172100-custom-html-validation-when-inserting-using-php/#findComment-907392 Share on other sites More sharing options...
JonnoTheDev Posted August 27, 2009 Share Posted August 27, 2009 There are many non-paired tags that would need re-formatting however you can do this in one fowl swoop but you will need the 'php html tidy' extension. Read docs to install i.e linux: yum install php-tidy Convert the string to xhtml using <?php $string = "<img src='test.gif'><br><img src='test.gif'>"; $tidyConfig = array('output-xhtml' => true); $string = tidy_parse_string($string, $tidyConfig, 'UTF8'); // display the new output print "<xmp>".$string."</xmp>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/172100-custom-html-validation-when-inserting-using-php/#findComment-907396 Share on other sites More sharing options...
matfish Posted August 27, 2009 Author Share Posted August 27, 2009 Thats great thanks - I'll give it a go Quote Link to comment https://forums.phpfreaks.com/topic/172100-custom-html-validation-when-inserting-using-php/#findComment-907401 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.