PHP, fixing html tags in JavaScript.
Posted: Wed Aug 19, 2009 12:20 pm
Ok everyone knows that </tag> is not valid in any JavaScript on a the page. It has to be <\/tag>. Only in the HTML can a closing tag be listed. So I am trying to get all my pages to XHTML standards, but I have some pesky JavaScript that is loading variables for certain things on my site. I can't add a second line of variables because they are set in other pages and don't want to change them because some are displayed outside of JavaScript tags. Plus it is a big rewrites so I came up with a simple solution I thought, but then I remember escaping things in PHP is my weak area. It just gets too confusing for me now. I read it up and still don't get it. I'm banging my head over here
Ok I found this simple solution, all I have to do is edit the return contents if it is going to be in a part of JavaScript in the page.
This is a simplified version of what I want to do, but only if that worked.
If I close the ending tag in the tags in the JavaScript it will be XHTML compatible.
Ok I found this simple solution, all I have to do is edit the return contents if it is going to be in a part of JavaScript in the page.
Code: Select all
return preg_replace('</','<\/', $content);
If I close the ending tag in the tags in the JavaScript it will be XHTML compatible.