Просмотр поста

.
Jahak

Интересно?

class String (+/-)

<?php

/**
 * @author Jahak <ya.jahak@yandex.ru>
 * @copyright (c) 2015, Jahak
 */
class String {

    /**
     * @param type $string
     * @return type
     */
    public static function e( $string = NULL ) {
        if ( static::isNull( $string ) ) {
            return htmlentities( $string, ENT_QUOTES, 'UTF-8' );
        }
        return;
    }

    /**
     * @param type $string
     * @return type
     */
    private static function isNull( $string ) {
        return !is_null( $string ) && '' !== $string;
    }

}

/*
 * Example
 */
header( 'Content-Type: text/html; charset=utf-8' );

$text = isset( $_GET['text'] ) ? $_GET['text'] : NULL;

if ( NULL !== String::e( $text ) ) {
    echo '<b>', String::e( $text ), '</b><br>';
}
?>
<form action="?">
    <input type="text" name="text"<?php
    echo ('' !== $text ? ' value="' . (NULL === String::e( $text ) ? ('' === $text
                    ? '' : String::e( '<script>alert("XSS");</script>' )) : String::e( $text )) . '"'
            : '')
    ?>>
    <input type="submit">
</form>