Html::clean PHP Method

clean() static public method

Clean display value deleting html tags
static public clean ( $value, $striptags = true, $keep_bad = 2 ) : clean
$value string: string value
$striptags bool: strip all html tags
$keep_bad int: 1 : neutralize tag anb content, 2 : remove tag and neutralize content
return clean value
    static function clean($value, $striptags = true, $keep_bad = 2)
    {
        $value = Html::entity_decode_deep($value);
        // Clean MS office tags
        $value = str_replace(array("<![if !supportLists]>", "<![endif]>"), '', $value);
        if ($striptags) {
            // Strip ToolTips
            $specialfilter = array('@<div[^>]*?tooltip_picture[^>]*?>.*?</div[^>]*?>@si', '@<div[^>]*?tooltip_text[^>]*?>.*?</div[^>]*?>@si', '@<div[^>]*?tooltip_picture_border[^>]*?>.*?</div[^>]*?>@si', '@<div[^>]*?invisible[^>]*?>.*?</div[^>]*?>@si');
            $value = preg_replace($specialfilter, '', $value);
            $value = preg_replace("/<(p|br|div)( [^>]*)?" . ">/i", "\n", $value);
            $value = preg_replace("/(&nbsp;| | )+/", " ", $value);
        }
        $search = array('@<script[^>]*?>.*?</script[^>]*?>@si', '@<style[^>]*?>.*?</style[^>]*?>@si', '@<title[^>]*?>.*?</title[^>]*?>@si', '@<!DOCTYPE[^>]*?>@si');
        $value = preg_replace($search, '', $value);
        // Neutralize not well formatted html tags
        $value = preg_replace("/(<)([^>]*<)/", "&lt;\$2", $value);
        include_once GLPI_HTMLAWED;
        $value = htmLawed($value, array('elements' => $striptags ? 'none' : '', 'keep_bad' => $keep_bad, 'comment' => 1, 'cdata' => 1));
        $value = str_replace(array("\r\n", "\r"), "\n", $value);
        $value = preg_replace("/(\n[ ]*){2,}/", "\n\n", $value, -1);
        return trim($value);
    }

Usage Example

Example #1
0
 /**
  * @see CommonDBTM::getName()
  **/
 function getName($options = array())
 {
     if ($rule = getItemForItemtype(static::$itemtype)) {
         return Html::clean($rule->getMinimalCriteriaText($this->fields));
     }
     return NOT_AVAILABLE;
 }
All Usage Examples Of Html::clean
Html