#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Question Need help understanding how to undo htmlspecialchars


    Hi,

    New to the forum and need a little help undoing the affects of some php code.

    I've been told i need change $alt and $title variables after the extract($params); section in order to get image rollovers to stop showing html code in my title tag. I know it has to do the htmlspecialchars section but just don't know how to write it properly.

    Can someone assist me in how i need to rewrite this code snippet to be achieve my end result of just showing the html output and not the actual source code.

    Here's the code ->

    Code:
    extract($params); if(empty($img)) return false; if(empty($medium)) $medium = $img; if(empty($thumb)) $thumb = $img; if(empty($id)) $id = md5($img); if(!empty($title)) { $title = htmlspecialchars(htmlspecialchars_decode($title, ENT_QUOTES)); if(empty($alt)) { $alt = $title; } else { $alt = htmlspecialchars(htmlspecialchars_decode($alt, ENT_QUOTES)); } $title = " title=\"{$title}\""; } else { $title = ''; if(empty($alt)) { $alt = ''; } else { $alt = htmlspecialchars(htmlspecialchars_decode($alt, ENT_QUOTES)); } }
    Thanks in advance.

    Ryan
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,122
    Rep Power
    9398
    That advice sounds suspicious. You cannot have HTML in the title attribute of anything - it has to be escaped.
    Code:
    Correct:   title="This word is <b>bold</b>"
    Incorrect: title="This word is <b>bold</b>"
    If you're using something that turns the title tooltip into some Javascript-powered thing then the problem is in whatever that Javascript is: it's using the title attribute value as text when it should be using it as HTML.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0
    Hi,

    Your example here
    Code:
    Incorrect: title="This word is <b>bold</b>"
    Is what is showing in my title. I need to fix it so that it just shows "This word is bold".

    Please advise on how I can do that. Maybe I explained it backwards. I can give you the URL and point out what's going on if that helps.

    Ryan

IMN logo majestic logo threadwatch logo seochat tools logo