php - 如何正确地将外语名称编码为 php 中 .txt 文件的名称
问题描述
我想将人名编码为.txt
文件名
现在我使用下面的代码将名称设为小写,去掉空格并且没有重音字符:
$raw_authorname = 'Charlène Rodriës';
$stripped_authorname = preg_replace("/[^a-z.]+/i", "", $raw_authorname); // strip accented chars out authorname
$stripped_authorname = preg_replace('/\s+/', '', $stripped_authorname); // strip out spaces
$stripped_authorname = strtolower($stripped_authorname); // make lowercase
echo $stripped_authorname; // output: charlnerodris
//And the txt file will be: charlnerodris.txt
这适用于拉丁字母。当名称例如是俄罗斯名称时会出现问题:Юлия Преснякова
我无法.txt
使用此名称创建文件:Юлия Преснякова.txt
阿拉伯名称存在相同问题。所以我认为; 也许最好对名称进行编码并.txt
使用编码名称创建一个文件。对这些名称进行编码的最合适方法是什么?或者有没有更好的方法来相应地更改名称,我可以始终为 txt 文件创建一个名称?
解决方案
推荐阅读
- vuejs2 - Vue 数据“计数器”不会在站点切换时迭代(但会在控制台中计数)
- cassandra - CQLSSTableWriter:使用 sstablesloader 摄取后是否需要压缩?
- reactjs - 如何在 React-Bootstrap 中实现下拉动画?
- c# - 预制空 Unity C#
- python - 从 vscode 中的目录运行 .py 和文件
- visual-studio - Visual Studio 搜索/替换为本地函数名称
- python - 为什么每次使用 reshape 多次调用张量都会改变其值
- python - 从 Sphinx 文字中排除注释包括
- javascript - 在选择框的更改选项上动态创建 Javascript 映射对象
- java - 使用 Java 从 Apache Phoenix 获取记录时响应缓慢