Skip to content

Instantly share code, notes, and snippets.

@stemar
Last active May 23, 2016 22:47
Show Gist options
  • Save stemar/5188900 to your computer and use it in GitHub Desktop.
Save stemar/5188900 to your computer and use it in GitHub Desktop.
A UTF-8 compatible htmlspecialchars() with optional arguments. An example of a function with optional arguments.
<?php
function hsc($value, $args=NULL) {
$default_args = array('flags'=>ENT_COMPAT, 'encoding'=>'UTF-8', 'double_encode'=>FALSE);
extract(array_merge($default_args, (array)$args));
return htmlspecialchars((string)$value, (int)$flags, (string)$encoding, (bool)$double_encode);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment