php - 如何从html文件中的php代码打开文件

标签 php html ini

我有“.html”文件并在其中运行 php 代码。 php 代码应该打开“.ini”文件。

".ini" file:
blast+: blast+\bin

blastn: test_na_db => Nucleotide test database
blastp: test_aa_db => Protein test database
blastx: test_aa_db => Protein test database
tblastn: test_na_db => Nucleotide test database
tblastx: test_na_db => Nucleotide test database


".html" file:
<td valign=top>&nbsp;&nbsp;&nbsp;Database(s)</td>
<td>
<?php
$fp = fopen ("./filename.ini", "r");
if(!$fp) {
    echo "<p><strong> Error: Couldn't open file filename.ini </strong></p></body></html>";
    exit;
}
while(!feof($fp)) {
    $blastdbstring = rtrim(fgets($fp));
    if (!$blastdbstring) {
        continue;
    }
    if (!preg_match("/^\s*#/", $blastdbstring)) {
        $blastdbArray = preg_split('/:/', $blastdbstring);  
        $blastProgram = $blastdbArray[0];
        $dbString = $blastdbArray[1];

        if ($blastProgram == "blast+") {
            echo "<input type='hidden' name= 'blastpath' value='$dbString'>";
        }else {
            if (preg_match("/^\s*(.*?)\s*$/", $blastProgram, $match)) {
                $blastProgram = $match[1];
            }
            if (preg_match("/^\s*(.*?)(\s*|\s*,\s*)$/", $dbString, $match)) {
                $dbString = $match[1];
            }
            $dbString = preg_replace("/\s*=>\s*/", "=>", $dbString);
            if (preg_match("/,/", $dbString, $match)) {
                $dbString = preg_replace("/\s*,\s*/", ",", $dbString);
            }       
            echo "<input id='$blastProgram' type='hidden' name='blastdb[]' value='$dbString'>";
        }
    }   
}
fclose($fp);

?>
<select id="dbList" size=4 multiple="multiple" name ="patientIDarray[]">
<script type="text/javascript">
    here call js function that create options depend on the selection of previous question
</script>

</select>
</td>

每次我收到此错误消息时: 无法打开文件 filename.ini!!!!

“.html”文件和“.ini”文件在同一目录下。

我可以完全控制那个“.ini”文件

有什么建议吗?

最佳答案

您可能想使用 parse_ini_file

// Parse without sections
$ini_array = parse_ini_file("sample.ini");
print_r($ini_array);

// Parse with sections
$ini_array = parse_ini_file("sample.ini", true);
print_r($ini_array);

http://php.net/manual/en/function.parse-ini-file.php

关于php - 如何从html文件中的php代码打开文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35407651/

相关文章:

c++ - 获取找到给定选项的 INI 文件行号的跨平台方法

php - 更改为 php.ini 无效

c - 通过网页获取ini文件的问题

php - 为什么 Magento 注销没有清除当前 session 数据?

php - 如何从 MYSQL 定义当前用户 ID?

html - 页脚不粘

html - 如何在不使用绝对位置的情况下将 Logo 图像和菜单项对齐在一行中?

php - 视口(viewport)不缩放到中心

php - 在请求播放之前,如何阻止嵌入的声音片段下载到浏览器缓存中?

php - 如何防止 Bootstrap 轮播图像堆叠? HTML/CSS(使用PHP显示图片)