php如何获取文件内容?

例如:test.ini文件的内容如下
[group]
myname=**
myage=**
mysex=**

用php如何获得myage的值
最新回答
我阅君心

2024-01-09 11:35:50

PHP 中的 file_get_contents() 函数可以实现

file_get_contents() 函数把整个文件读入一个字符串中。

和 file() 一样,不同的困轮是 file_get_contents() 把文件读入一个字符串。

file_get_contents() 函数是用于将文森掘件的内容读入到一个字符串中的首选方法。如果操作系统支汪春信持,还会使用内存映射技术来增强性能。

例如:

<?php
echo file_get_contents("test.txt");
?>
几闲人

2023-07-19 16:44:03

我想毁培可瞎键以用磨余巧
file_get_contents();

正则匹配来获取
preg_match()
风轻花落早

2022-03-04 05:18:19

$content = file_get_contents('test.ini'岩雹芹);
$str = str_replace("\n", "&",str_replace("\肆仿r", "",$content));
$array = array();
parse_str($str, $array);
print_r($array);
echo $array['myage'粗毕];
$array['myage']就是myage的值。
薅藤已蔓蔆

2020-08-20 05:58:20

parse_ini_file

如果你的ini标准的话~
给十年后的我

2024-01-20 07:01:58

那你就读文件,取值呗...
收起 2条折叠回答