3v4l.org

run code in 300+ PHP versions simultaneously
<?php 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; ?>
Output for git.master, git.master_jit, rfc.property-hooks
BBCTVL This is an an57noying string to use

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:
50.78 ms | 401 KiB | 8 Q