PHP FILTER_SANITIZE ? Think RegEx Instead

keep calm and sanitizeSometimes it is better to use a clear and simple solution that has better readability over a ‘template thinking’. over-thinking is a good thing, it keeps your mind sharp.

considering the fact that using FILTER_SANITIZE_SPECIAL_CHARS with FILTER_FLAG_STRIP_HIGH will probably send you co-friend/team-mate programmer to dig through http://php.net, which is not nice..

…sometimes RegEx is just the better choice, especially when you are working on a custom solution,

Here is a clean filter_input to SANITIZE YouTube Video-ID-like value,

<?php
$video_id = filter_input(INPUT_GET, 'video_id', FILTER_CALLBACK, ['options' => function ($value) {
  return preg_replace("#[^_0-9a-z\-]#im", "", $value);
}]);
?>