3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php public function sanitiseFilename($input) { // // See #3271 // Code from http://stackoverflow.com/a/2021729/3929494 // // Remove anything which isn't a word, whitespace, number // or any of the following characters -_~,;:[](). // If you don't need to handle multi-byte characters // you can use preg_replace rather than mb_ereg_replace // Thanks @Łukasz Rysiak! $output = mb_ereg_replace("([^\w\s\d\-_~,;:\[\]\(\).])", '', $input); // Remove any runs of periods (thanks falstro!) $output = mb_ereg_replace("([\.]{2,})", '', $output); // Remove any runs of spaces, e.g. " / " becomes " " which is ugly $output = mb_ereg_replace(" ", " ", $output); return $output; } echo sanitiseFilename("BBC/TVL") . PHP_EOL; echo sanitiseFilename("This%%% is an an$57noy£ing string/ to / use") . PHP_EOL; ?>
based on 0ROSt
Output for 7.0.0
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting end of file in /in/Wpom4 on line 3
Process exited with code 255.
Output for 5.4.10 - 5.6.16
Parse error: syntax error, unexpected 'public' (T_PUBLIC) in /in/Wpom4 on line 3
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected T_PUBLIC in /in/Wpom4 on line 3
Process exited with code 255.