1. Go to this page and download the library: Download luizbills/v 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/ */
luizbills / v example snippets
<?= 'Name: ' . v( 'luiz', 'upper' )
// escape by default
echo v( '<p>hello</p>' ); // => <p>hello</p>
// same as
echo v( '<p>hello</p>', 'escape' ); // => <p>hello</p>
// or you can strip all tags
echo v( '<p>hello</p>', 'strip_tags' ); // => hello
// or strip only "evil" tags: <script>, <style>, <iframe> and <link>
echo v( '<p>hello</p><script>evilFunc();</script>', 'safe_html' ); // => <p>hello</p>
// and to disable autoescaping, use the `raw` filter
echo v( '<p>hello</p>', 'raw' ); // => <p>hello</p>
// you can do like this
echo v( 1567973782, 'date("d/m/Y")' ); // => 08/09/2019
// or like this (without double-quotes)
echo v( 1567973782, 'date(d/m/Y)' ); // => 08/09/2019
// Note: always use double-quotes if you need whitespaces in your argument,
// otherwise they will be deleted (with `trim`).
// inline function
$upper = function ( $value ) {
return strtoupper( $value );
}
echo v( 'ok', $upper ); // => OK
// or global functions (add an @ before)
echo v( 'ok', '@strtoupper' ); // => OK
// or methods
echo v( 'ok', [ 'MyClass', 'my_method' ] );
// The `v_register_filter` accepts an optional third argument called 'context'.
// Note: the default context is 'root'.
function exclaim_callback_v1 ( $value, $args ) {
return $value . '!';
}
v_register_filter( 'exclaim', 'exclaim_callback_v1' ); // context = "root"
function exclaim_callback_v2 ( $value, $args ) {
return $value . '!!!!!';
}
v_register_filter( 'exclaim', 'exclaim_callback_v2', 'v2' ); // context = "v2"
echo v( 'foo', 'exclaim' ); // => foo!
// change the context to "v2"
v_set_context( 'v2' );
echo v( 'foo', 'exclaim' ); // => foo!!!!!
// reset the context
v_reset_context(); // same as: v_set_context( 'root' );
echo v( 'foo', 'exclaim' ); // => foo!
// note: all built-in (or default) filters are available in any context
// this function accepts an Array, where each key is a filter
v_load_extension( [
// `exclaim` is now a default filter
'exclaim' => function ( $value, $args ) {
return $value . '!';
}
] );
// use the `log` filter to log the current value with error_log function
echo v( 'hello', 'upper', 'log' );
// => logs: [v log] (string) "HELLO"
// You can also pass a ID to log filter, this help you identify outputs
echo v( 'hello', 'log(before upper)', 'upper' );
// => logs: [v log @ before upper] (string) "hello"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.