PHP Escape String

function escape($str) {
    return str_replace(
        array( '&',     '<',    '>',    '"',      '\''),
        array( '&amp;', '&lt;', '&gt;', '&quot;', '&#039;'),
        $str
    );
}

NOTE: &apos; is not used as it is not a valid HTML entity reference.

Did this help you? Please let me know with a comment. Thank you
Posted .

Comments (RSS)

Leave a comment