Thursday 15 September 2016

PHP Validation Function for HTML Safe

Simple php function to validate html tags in given content. In some cases we need to check if the given string contains html tags in order to avoid hacking attends and also to avoid unwanted elements changing the layout of our site.

function validateHtmlSafe($value) {
    return (bool)(!preg_match("/<(.*)>.*<$1>/", $value));
}

No comments:

Post a Comment