form/FormPlus.php
/**
     * Make veriable safe to display as HTML text
     * Only process one layer string data(the data type could be: number/boolean/string/object/array) except
     * $is_array is true, could process 2 layer data(top layer must be array)
     * @param mixed $data
     * @param boolean $is_array
     * @throws InvalidArgumentException
     * @return mixed
     */
Make veriable safe to display as HTML text
Only process one layer string data(the data type could be: number/boolean/string/object/array) except
$is_array is true, could process 2 layer data(top layer must be array)
@param mixed $data
@param boolean $is_array
@throws InvalidArgumentException
@return mixed
Make veriable safe to display as HTML text Only process one layer string data ( the data type could be : number / boolean / string / object / array ) except $is_array is true could process 2 layer data ( top layer must be array ) @param mixed $data @param boolean $is_array @throws InvalidArgumentException @return mixed
public function toSafeHtml($data, $is_array = FALSE) {
        $toSafeHtml_func = function ($data) {
            if (empty($data) || is_numeric($data) || is_bool($data)) {
                return $data;
            }
            if (is_string($data)) {
                return htmlspecialchars($data, ENT_QUOTES);
            }
            if (is_object($data)) {
                $array = get_object_vars($data);
                foreach ($array as $key => $value) {
                    if (is_string($value)) {
                        $data->$key = htmlspecialchars($value, ENT_QUOTES);
                    }
                }
                return $data;
            }
            if (is_array($data)) {
                foreach ($data as $key => $value) {
                    if (is_string($value)) {
                        $value = htmlspecialchars($value, ENT_QUOTES);
                    }
                    $data[$key] = $value;
                }
                return $data;
            }
            return $data;
        };
        if ($is_array) {
            if (! is_array($data)) {
                throw new \InvalidArgumentException('Invalid toSafeHtml parameters');
            }
            foreach ($data as $key => $value) {
                $data[$key] = $toSafeHtml_func($value);
            }
            return $data;
        }
        return $toSafeHtml_func($data);
    }
public function toSafeHtml ( $ data , $ is_array = FALSE ) { $ toSafeHtml_func = function ( $ data ) { if ( empty ( $ data ) || is_numeric ( $ data ) || is_bool ( $ data ) ) { return $ data ; } if ( is_string ( $ data ) ) { return htmlspecialchars ( $ data , ENT_QUOTES ) ; } if ( is_object ( $ data ) ) { $ array = get_object_vars ( $ data ) ; foreach ( $ array as $ key => $ value ) { if ( is_string ( $ value ) ) { $ data -> $ key = htmlspecialchars ( $ value , ENT_QUOTES ) ; } } return $ data ; } if ( is_array ( $ data ) ) { foreach ( $ data as $ key => $ value ) { if ( is_string ( $ value ) ) { $ value = htmlspecialchars ( $ value , ENT_QUOTES ) ; } $ data [ $ key ] = $ value ; } return $ data ; } return $ data ; } ; if ( $ is_array ) { if ( ! is_array ( $ data ) ) { throw new \ InvalidArgumentException ( 'Invalid toSafeHtml parameters' ) ; } foreach ( $ data as $ key => $ value ) { $ data [ $ key ] = $ toSafeHtml_func ( $ value ) ; } return $ data ; } return $ toSafeHtml_func ( $ data ) ; }
Make veriable safe to display as HTML text
 Only process one layer string data(the data type could be: number/boolean/string/object/array) except
 $is_array is true, could process 2 layer data(top layer must be array)
 @param mixed $data
 @param boolean $is_array
 @throws InvalidArgumentException
 @return mixed
Make veriable safe to display as HTML text Only process one layer string data ( the data type could be : number / boolean / string / object / array ) except $is_array is true could process 2 layer data ( top layer must be array ) @param mixed $data @param boolean $is_array @throws InvalidArgumentException @return mixed