[RESOLVED] Adding quotes to echo'd HTML attributes
In the admin area, sometimes sloppy HTML code gets put in there and they don't put quotes around HTML attributes, ie:
HTML Code:
<a href=www.imanidiot.com>I have no idea what I'm doing</a>
This HTML is stored in a table in the database. How can I echo that HTML with quotes around attributes so it is like:
HTML Code:
<a href="www.imanidiot.com">I have no idea what I'm doing</a>
Re: Adding quotes to echo'd HTML attributes
If it's stored without quotes in the database in the first place, consider getting a better input 'control or WYSIWYG editor, ideally you shouldn't have to be dealing with badly formatted HTML.
If you have HTML stored in the database without the attribute quotes, then find a regular expression that will identify any attribute value. Perform the replacements when the data is being read out to wherever it is you want it read out.
Re: Adding quotes to echo'd HTML attributes
I don't know regular expressions too well...I'm making changes to an existing admin area/website, and the code is encoded with Zend Encoder (or something like that), so unfortunately, modifying the page that stores the HTML/adding a WYSIWYG editor is not possible. :(
Anyone here good with regular expressions and could give me a hand?
I spent a lot of time bringing down the HTML validation errors from his old coder from over 16,000 to 10, and now when this HTML output is shown, it raises that number a lot and more importantly, screws up the display on his page.
Re: Adding quotes to echo'd HTML attributes
Use the DOM extension to load the HTML into a DOM tree and then render it back into well-formed HTML.
Re: Adding quotes to echo'd HTML attributes
You mean using JavaScript? What if the person viewing the page has JavaScript disabled? :confused:
Guess I will just go look into regular expressions and figure it out.
Re: [RESOLVED] Adding quotes to echo'd HTML attributes
Re: [RESOLVED] Adding quotes to echo'd HTML attributes
Hm, seems like a lot to learn for this, was hoping for a quick fix but I am reading into it, thanks penagate. :cool:
I will post what I come up with.