', '"', "'", '-', ]; $replacement = [ '&', '<', '>', '"', ''', '-', ]; $str = str_replace($original, $replacement, $str); // Decode the temp markers back to entities $str = preg_replace('/' . $temp . '(\d+);/', '&#\\1;', $str); if ($protect_all === true) { return preg_replace('/' . $temp . '(\w+);/', '&\\1;', $str); } return $str; } }