PHP code example of popphp / pop-filter
1. Go to this page and download the library: Download popphp/pop-filter 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/ */
popphp / pop-filter example snippets
$filter = new Pop\Filter\Filter('strip_tags');
$values = [
'username' => '<b>admin</b>',
'email' => '<a href="mailto:[email protected] ">[email protected] </a>'
];
$values = $filter->filter($values);
namespace MyApp\Model
use Pop\Filter\FilterableTrait;
class User
{
use FilterableTrait;
/**
* Filter values
*
* @param array $values
* @return array
*/
public function filter(array $values)
{
foreach ($this->filters as $filter) {
foreach ($values as $key => $value) {
$values[$key] = $filter->filter($value, $key);
}
}
return $values;
}
}
$user = new User();
$user->addFilters([
'strip_tags',
new Pop\Filter\Filter('htmlentities', [ENT_QUOTES, 'UTF-8']),
]);
$values = [
'username' => '<script>"Admin"</script>',
'first_name' => '<b>John\'s</b>',
'last_name' => '<b>Doe</b>'
];
$values = $user->filter($values);
$filter = new Pop\Filter\Filter('strip_tags', null, 'username');
$values = [
'username' => '<b>admin</b>',
'email' => '<a href="mailto:[email protected] ">[email protected] </a>'
];
foreach ($values as $key => $value) {
$values[$key] = $filter->filter($value, $key);
}
text
$values = [
'username' => 'admin',
'email' => '[email protected] '
];
text
$values = [
'username' => '<b>admin</b>',
'email' => '[email protected] '
];