комментирование вкл/выкл сделаю
<?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># Jahak (14.02.2015 / 17:14)А мне кажется обратное...
Swank, Но это не быдлокод!
echo ('' !== $text ? ' value="' . (NULL === String::e( $text ) ? ('' === $text
? '' : String::e( '<script>alert("XSS");</script>' )) : String::e( $text )) . '"'
: '') private static function isEmpty( $string ) {
return empty($string);
}# L!MP (14.02.2015 / 20:19)тоже ненадо. у него нет данных внутри класса, их и проверять не за чем внутри оного.
Jahak,private static function isEmpty( $string ) { return empty($string); }
Не то же самое?