#1
  1. Purple is a Fruit
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Ireland
    Posts
    404
    Rep Power
    170

    Escaping HTML Strings Within MySQL


    Hey,

    I am wondering if it is possible to escape HTML strings within MySQL. I want to select a list of criteria from a MySQL table and concatenate them together to form a HTML select menu. However, some of the category names have HTML special characters in them (like < > and &). I am wondering if there is an internal function in MySQL to escapte HTML characters or would it be necessary to write a stored procedure or something along those lines? (Unfortunately I don't have access to MySQL 5.0 so I can't use Stored Procedures).

    Thanks for you time!
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,150
    Rep Power
    4274
    use the replace function

    select replace(replace(replace(categoryname,'&','&amp;'),'<','&lt;'),'>','&gt;') as newname
    from ...
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo