PHP code example of darkghosthunter / larasane

1. Go to this page and download the library: Download darkghosthunter/larasane 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/ */

    

darkghosthunter / larasane example snippets




use DarkGhostHunter\Larasane\Facades\Sanitizer;

$input = 'Trust <script src="https://malicio.us/code.js"></script> me!';

echo Sanitizer::input($input)->sanitize($input); // "Trust me!"



return [
    'max_length' => 1000,
    'allow_code' => [
        'basic',
    ],
    'security' => [
        'enforced_domains' => null,
        'enforce_https' => null,
        'image_data'    => false,
        'allow_mailto'  => false,
    ],
    'tags' => [
        'div' => 'class',
        'img' => ['src', 'alt', 'title', 'class'],
        'a' => ['class', 'target'],
        'ul' => 'class',
        'ol' => 'class',
        'li' => 'class',
    ]
];

return [
    'max_length' => 1000,
];

$sanitized = Sanitizer::for($input)->maxLength(200);

return [
    'allow_code' => [
        'basic', /* 'list', 'table', 'image', 'code', 'iframe', 'details', 'extra' */
    ],
];

$sanitized = Sanitizer::for($input)->allowCode('basic', 'list', 'table');

return [
    'security' => [
        'enforce_hosts' => null,
        'enforce_https' => null,
        'image_data'    => false,
        'allow_mailto'  => false,
    ],
];

$input = Sanitizer::for($input)
                  ->hosts('myapp.com')
                  ->enforceHttps(true)
                  ->imageData(true)
                  ->allowMailto(true);

return [
    'tags' => [
        'div' => 'class',
        'img' => ['src', 'alt', 'title', 'class'],
        'a' => ['class', 'target'],
        'ul' => 'class',
        'ol' => 'class',
        'li' => 'class',
    ]
];

$sanitized = Sanitizer::for($input)->tagAttributes('a', 'class', 'target');


use HtmlSanitizer\SanitizerBuilder;
use App\Sanitizer\MyExtension;

/**
 * Register the application services.
 *
 * @return void
 */
public function register()
{
    $this->app->extend(SanitizerBuilder::class, function (SanitizerBuilder $builder) {
        return $builder->registerExtension(new MyExtension());
    });
}