note 79678 added to function.preg-replace
| From: | ulfdotreimersattesadotcom at osu1 dot php dot net | Date: | Fri, 07 Dec 2007 18:28:02 +0000 |
| Subject: | note 79678 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132934@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 194.145.210.4
Probable Submitter: 194.175.243.100
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/79678
Del: integrated -- https://master.php.net/note/delete/79678/integrated
Del: useless -- https://master.php.net/note/delete/79678/useless
Del: bad code -- https://master.php.net/note/delete/79678/bad+code
Del: spam -- https://master.php.net/note/delete/79678/spam
Del: non-english -- https://master.php.net/note/delete/79678/non-english
Del: in docs -- https://master.php.net/note/delete/79678/in+docs
Del: other reasons-- https://master.php.net/note/delete/79678
Reject -- https://master.php.net/note/reject/79678
Search -- https://master.php.net/manage/user-notes.php