PHP code example of jakubboucek / legacy-escape

1. Go to this page and download the library: Download jakubboucek/legacy-escape library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jakubboucek / legacy-escape example snippets


echo 'Registered user: ' . $username;

use JakubBoucek\Escape\Escape;

echo 'Registered user: ' . Escape::html($username);

use JakubBoucek\Escape\Escape as E;

echo 'Registered user: ' . E::html($username);

echo '<a href="' . Escape::htmlHref($url) . '">' . Escape::html($label) . '</a>';
echo '<div data-options="' . Escape::htmlJsonAttr($options) . '"></div>';
echo '<script>const options = ' . Escape::js($options) . ';</script>';

use JakubBoucek\Escape\EscapeCss;

echo '<style>.label { color: ' . EscapeCss::color($cssColor) . '; }</style>';

use JakubBoucek\Escape\Escape;
use Nette\Utils\Html; 

$avatarUrl = 'https://example.com/avatar.png';
$username = 'John Doe <script>hack</script>';

$avatarImage = Html::el('img')->src($avatarUrl)->width(16);
echo Escape::html($avatarImage, ' ', $username);

// <img src="https://example.com/avatar.png" width="16"> John Doe &lt;script&gt;hack&lt;/script&gt;

echo \JakubBoucek\Escape\Escape::noescape($htmlContent);