示例#1
0
文件: ruleset.php 项目: joy2fun/phpvs
<?php

use PHPVS\Validator as V;
use PHPVS\Sanitizer as S;
use PHPVS\RuleSet;
require dirname(__DIR__) . '/src/bootstrap.php';
// sample input data
$input = array('name' => '', 'age' => 0, 'email' => 'php.html.js.cn', 'contact' => ['name' => 'foobar', 'website' => 'http://php.html.js.cn']);
$rules = array('name' => S::text()->required()->prepare(), 'age' => V::int(1)->defaulted(5)->prepare(), 'email' => V::email()->prepare(), 'contact' => RuleSet::setup(['name' => V::int()->prepare(), 'website' => V::email()->prepare()]));
$result = RuleSet::filter($input, $rules);
示例#2
0
文件: basic.php 项目: joy2fun/phpvs
<?php

use PHPVS\Validator as V;
use PHPVS\Sanitizer as S;
require dirname(__DIR__) . '/src/bootstrap.php';
if ($a = V::int()->valid(0)) {
    echo "valid int!\n";
} else {
    // invalid input
}
// attribute sanitizer
$title = "Title with 'some' <sepcial> characters.";
$title = S::attr()->filter($title);
echo $title, "\n";
// sanitizer with a default value
echo S::int()->filter("str", $default = 10), "\n";
// output 10
// callback to wrap string with a <pre> tag.
echo S::callback(function ($data) {
    return sprintf("<pre>%s</pre>", $data);
})->filter("something"), "\n";