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.

View this page on GitHub.
Posted .

Comments

Leave a Reply