note 79678 deleted from function.preg-replace by crell

From: Date: Fri, 01 Jul 2022 19:52:25 +0000
Subject: note 79678 deleted from function.preg-replace by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218868@lists.php.net to get a copy of this message
Note Submitter: ulf dot reimers at tesa dot com ---- Hi, as I wasn't able to find another way to do this, I wrote a function converting any UTF-8 string into a correct NTFS filename (see http://en.wikipedia.org/wiki/Filename). <?php function strToNTFSFilename($string) { $reserved = preg_quote('\/:*?"<>', '/'); return preg_replace("/([\\x00-\\x1f{$forbidden}])/e", "_", $string); } ?> It converts all control characters and filename characters which are reserved by Windows ('\/:*?"<>') into an underscore. This way you can safely create an NTFS filename out of any UTF-8 string.

« previous php.notes (#218868) next »