Results 1 to 7 of 7

Thread: [RESOLVED] Adding quotes to echo'd HTML attributes

  1. #1

    Thread Starter
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Resolved [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>

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  3. #3

    Thread Starter
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    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.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  5. #5

    Thread Starter
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Adding quotes to echo'd HTML attributes

    You mean using JavaScript? What if the person viewing the page has JavaScript disabled?

    Guess I will just go look into regular expressions and figure it out.

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [RESOLVED] Adding quotes to echo'd HTML attributes


  7. #7

    Thread Starter
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    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.

    I will post what I come up with.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width