PHP code example of baddiservices / safehtml

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

    

baddiservices / safehtml example snippets


...

use BADDIServices\SafeHTML\SafeHTML;

class DemoController extends Controller
{
    /** @var SafeHTML **/
    private $safeHTML;

    public function __construct(SafeHTML $safeHTML)
    {
        $this->safeHTML = $safeHTML;
    }

    public function IndexAction(Request $request)
    {
        $htmlContent = $request->input("content");
        if ($this->validate($htmlContent)) {
            // TODO: is valid HTML continue the process
        }
    }
}

...

$sanitizedHTML = $safeHTML->sanitizeHTML($content);

...

$sanitizedText = $safeHTML->sanitize($text);

...

$sanitizedURL = $safeHTML->sanitizeURL($url);