gpt4 book ai didi

PHP is_dir : Strange behaviour with special characters

转载 作者:搜寻专家 更新时间:2023-10-31 22:08:29 25 4
gpt4 key购买 nike

关于带有特殊字符的 is_dir,我有一个奇怪的行为:äöüàéè。

如果先写入特殊字符(例如 'à tést'、'école wat'),则代码可以正常工作(检测文件夹)。

但是如果除了特殊字符之外的任何字符都写在特殊字符之前(例如'tést','the école')那么它就不起作用。

这是我正在使用的代码。我试图强制转换文本以使其工作,但它不会。

if ( is_dir(iconv("UTF-8", "ISO-8859-1", "{$text}")) ){ //Do Something }

最佳答案

尝试使用 mb_convert_encoding。

if ( is_dir(mb_convert_encoding( "{$text}", "ISO-8859-1", "UTF-8" )) ){ //Do Something }

我猜 $text 而不是 "{$text}"也应该这样做

作为最后的建议,请查看此评论; http://www.php.net/manual/en/function.mb-convert-encoding.php#85752

关于PHP is_dir : Strange behaviour with special characters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15134046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com