Php 用$symbol解析\u ini\u文件问题
我有一个settings.ini.php文件,其中包含我的数据库详细信息Php 用$symbol解析\u ini\u文件问题,php,database,connection,Php,Database,Connection,我有一个settings.ini.php文件,其中包含我的数据库详细信息 ;<?php return; ?> [SQL] host = localhost user = root password =Gohead123$ dbname = nri_demo 我得到的输出像 Characters ?{}|&~![()^" must not be used anywhere in the key and have a special meaning in the value.
;<?php return; ?>
[SQL]
host = localhost
user = root
password =Gohead123$
dbname = nri_demo
我得到的输出像
Characters ?{}|&~![()^" must not be used anywhere
in the key and have a special meaning in the value.
如何解决此问题?请帮助我。首先-您可以将
.ini
文件移出public\u html
目录,使其无法访问,或者使用配置
目录中的.htaccess
。这种PHP“黑客”不是一个好的选择
此外,我在PHP文档中发现了一个注意事项:
parse_ini_file('settings.ini.php', false, INI_SCANNER_RAW)
您可以尝试使用INI\u SCANNER\u RAW
标志,可能会有所帮助
顺便说一句,考虑将配置更改为JSON文件。尝试使用as
INI\u SCANNER\u RAW的第三个参数
Array ( [host] => localhost [user] => root [password] => Gohead123$ [dbname] => nri_demo )
输出:
为我工作,你使用的是哪个版本的php?@Chethan Ameta php version 7.0.15tryparse_ini_file($str,false,ini_SCANNER_RAW)
@ChetanAmeta-Thankyew这么多..正在工作,请以commemnt的身份回答,这样我就可以接受了
Characters ?{}|&~![()^" must not be used anywhere
in the key and have a special meaning in the value.
parse_ini_file('settings.ini.php', false, INI_SCANNER_RAW)
Array ( [host] => localhost [user] => root [password] => Gohead123$ [dbname] => nri_demo )