- var_dump: documentation ( source)
- preg_replace: documentation ( source)
<?php
$name = 'my file:name?w[ith/illegal*cha]racters\"that<are>not\allowed|here.txt';
$newName = preg_replace('/[\?\/:|<>*\[\]\(\)\$%\{\}@~\s]/', '_', $name);
var_dump($newName);