PHP 解析 INI 文件给出有关等号的错误
我正在尝试解析一个 INI 文件,该文件将 URL 作为要解析的变量之一。问题是,URL 中包含“=”,并且 parse_ini_file 会输出错误。我试图逃避这个角色,但无济于事。其他人也会遇到这种情况吗?如果是这样,有人修复了吗?
I'm trying to parse out an INI file that has a URL as one of the variables to parse. Problem is, the URL contains a '=' in it, and parse_ini_file spits out an error. I tried to escape the character, but to no avail. Does this happen to anybody else? And if so, has anybody fixed it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否将该值括在引号中?只要值周围有引号,值中包含 = 就不会有问题。例子:
Have you enclosed the value in quotes? It shouldn't be a problem to have = in the value as long as you have quotes around your value. Example:
更好的方法是使用
INI_SCANNER_RAW
作为parse_ini_file
的第三个参数much better would be use
INI_SCANNER_RAW
as 3rd parameter ofparse_ini_file
我也遇到了同样的问题,这让我发疯了!问题最终变得很愚蠢......我在 Windows 中创建了 .ini 文件,使用了一个重命名为 .ini 的文件。显然,PHP 可以看到一些标记,但在我的 Notepad++ 中却看不到。
我删除了 .ini 并在我的 Linux 主机上创建了一个。这解决了问题。如果您在 Windows 上使用 WAMP 或 XAMPP,请尝试仅使用记事本创建一个新文件,这会忽略任何标记。
我知道这是一个老话题,但我最终在这里寻找同样的问题,所以它可能对其他人有帮助。
I had the same problem and it drove me insane! The problem ended up being something silly ... I had created the .ini file in Windows, using a file that I renamed to .ini. Apparently there was some markup left which was seen by PHP, but not in my Notepad++.
I deleted the .ini and created one on my Linux host. This resolved the problem. If you're using WAMP or XAMPP on Windows, try to create a new file with just notepad, which disregards any markup.
I know this is an old topic, but I ended up here looking for the same problem, so it might help someone else.
这是修复 parse_ini_* 等号问题的快速解决方案。您还可以使用正则表达式、爆炸数组等。
Here is a quick solution to fix parse_ini_* problems with equality sign. You can use also regex, exploding arrays, etc.