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.

This post is available on GitHub.
Posted .

Comments

Leave a Reply