3v4l.org

run code in 300+ PHP versions simultaneously
<?php function validate_length ($options = ['min_length' => 1, 'max_length' => null], $filters = null) { return static function ($value = null) use ($options, $filters) { $len = strlen($value); if (isset($options['min_length']) && $len < $options['min_length']) { return false; } if (isset($options['max_length']) && $len > $options['max_length']) { return false; } if (null !== $filters) { return filter_var($value, ...$filters); //php 5.6+ array spread operator } return $value; }; } $a = [ 'a' => 'value', 'b' => '', 'c' => 'a@example.com', 'd' => 'This& is a 🍕 Test', ]; $email_filter = [FILTER_VALIDATE_EMAIL, ['flags' => FILTER_FLAG_EMAIL_UNICODE]]; $string_filter = [FILTER_SANITIZE_STRING, ['flags' => FILTER_FLAG_ENCODE_AMP | FILTER_FLAG_STRIP_HIGH]]; $result = filter_var_array ($a, [ 'a' => ['filter' => FILTER_CALLBACK, 'options' => validate_length(['max_length' => 4])], 'b' => ['filter' => FILTER_CALLBACK, 'options' => validate_length(['min_length' => 1])], 'c' => ['filter' => FILTER_CALLBACK, 'options' => validate_length(['min_length' => 1, 'max_length' => 20], $email_filter)], 'd' => ['filter' => FILTER_CALLBACK, 'options' => validate_length(['min_length' => 1], $string_filter)], ]); var_dump($result);
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in /in/83uXu on line 31 array(4) { ["a"]=> bool(false) ["b"]=> bool(false) ["c"]=> string(13) "a@example.com" ["d"]=> string(20) "This&#38; is a Test" }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
25.98 ms | 405 KiB | 5 Q