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

.
Jahak
html class (+/-)

Rakovskiy,
<?php

/**
 * html class
 */
class html {

    /**
     * @param string $href
     * @param string $name
     * @return type
     */
    public static function getLink( $href, $name ) {
        return '<a href="' . $href . '">' . $name . '</a>';
    }

    /**
     * @param string $src
     * @param string $alt
     * @return type
     */
    public static function getImage( $src, $alt ) {
        return '<img src="' . $src . '" alt="' . $alt . '">';
    }

    /**
     * @param string $string
     * @return type
     */
    public static function getText( $string ) {
        return htmlspecialchars( $string, ENT_HTML5, 'UTF-8' );
    }

    /**
     * @param array $pieces
     * @param type $ol_ul
     * @return type
     */
    public static function getList( $pieces, $ol_ul = 'ol' ) {
        return '<' . $ol_ul . '><li>' . implode( '</li><li>', $pieces ) . '</li></' . $ol_ul . '>';
    }

    /**
     * @param string $tag
     * @param string $string
     * @return type
     */
    public static function getTag( $tag, $string ) {
        return '<' . $tag . '>' . static::getText( $string ) . '</' . $tag . '>';
    }

}

echo html::getLink( '/', 'Article' ), '<br>';
echo html::getText( '<script>alert("XSS");</script>' ), '<br>';
echo html::getImage( 'http://localhost/logo-new.gif', 'logo' );
$pieces = [
    'text',
    'text1',
    'text2'
];
echo html::getList( $pieces );
echo html::getTag( 'b', '<script>alert("XSS");</script>' );