无法使用PHP从.ini读取所有行

时间:2014-03-11 05:56:47

标签: php

我试图读取.ini文件并读取所有键值。而我只能获得8个关键&价值对。这是我的代码。

<?php
$file = fopen("/home/bigc/Desktop/First.ini","r");

while(! feof($file)) {      
    $line_of_text = fgets($file);
    $parts = explode('=', $line_of_text);
    echo $parts[0] . $parts[1]. "<BR>";
}

fclose($file);
?> 

我的ini文件是:

GiftCertificateEmailSubject = "%s has sent you a gift certificate for %s"
Dear = "Dear"
GiftCertificateEmailIntro = "%s (%s) has sent you a %s gift certificate for <a     href='%s'>%s</a>. "
GiftCertificateEmailAttached = "Your gift certificate is attached to this email."
GiftCertificateEmailInstructions = "For instructions on how to redeem your gift certificate please <a href='%s/giftcertificates.php?action=redeem'>click here</a>."
GiftCertificateEmailExpiry = "You have until %s to use this gift certificate before it expires."
GiftCertificateEmailWarning = "Please download or print a copy of your gift certificate for safe keeping as gift certificates are non-transferable."
GiftCertificateEmailYouHaveReceived = "You have received a Gift Certificate for"
GiftCertificate = "Gift Certificate"
CertificateTo = "To"

有什么遗漏吗?

1 个答案:

答案 0 :(得分:2)

您的.ini阅读功能存在缺陷。您正在按'='进行拆分,但您的值包含字符'='。

将其修复为仅拆分一次(对于第一个'=') 或者使用标准的.ini解析函数,如评论中提到的Shomz。