PHP code example of chromabits / purifier

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

    

chromabits / purifier example snippets


    'providers' => [
        // ...
        'Chromabits\Purifier\PurifierServiceProvider',
    ]

return [
    "settings" => [
        "default" => [
            "HTML.SafeIframe" => 'true',
            "URI.SafeIframeRegexp" => "%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%",
        ],
        "titles" => [
            'AutoFormat.AutoParagraph' => false,
            'AutoFormat.Linkify' => false,
        ]
    ],
];



namespace Http\Controllers;

use Chromabits\Purifier\Contracts\Purifier;
use HTMLPurifier_Config;
use Illuminate\Http\Request;

/**
 * Class IndexController
 *
 * @package App\Http\Controllers;
 */
class IndexController {
	/**
	 * @var Purifier
	 */
	protected $purifier;
	
	/**
	 * Construct an instance of MyClass
	 *
	 * @param Purifier $purifier
	 */
	public function __construct(Purifier $purifier) {
		// Inject dependencies
		$this->purifier = $purifier;
	}
	
	/**
	 * Get index page
	 *
	 * @param Request $request
	 */
	public function getIndex(Request $request)
	{
		return $this->purifier->clean($request->input('first_name'));
	}
}

	// Using config entries from purifier.php
	$this->purifier->clean('This is my H1 title', 'titles');
	
	// Passing configuration from an array (inherits default config)
	$this->purifier->clean(
		'This is my H1 title',
		[ 'Attr.EnableID' => true ]
	);



namespace App\Providers;

use Chromabits\Purifier\Purifier;
use Illuminate\Support\ServiceProvider;

/**
 * ...
 */
class CustomPurifierServiceProvider extends ServiceProvider
{
    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        // Bind contract with concrete implementation
        $this->app->bind(
        	'Chromabits\Purifier\Contracts\Purifier',
        	function ($app) {
          		new Purifier($app, $app['config'], function (HTMLPurifier_Config $config) {
                		// Do stuff with $config here
                		return $config;
                }
            }
        );
    }
}