相关疑难解决方法(0)

PHP YAML解析器

有没有人知道PHP的YAML解析器?如果是这样,这个图书馆的优点和缺点是什么?

php parsing yaml

105
推荐指数
4
解决办法
5万
查看次数

php从文本文件中检索数据

想象一下,我有一个像这样的文本文件:

 Welcome to the text file!
 -------------------------
 Description1: value1
 Description2: value2
 Description containing spaces: value containing spaces
 Description3: value3
Run Code Online (Sandbox Code Playgroud)

将这些数据存储到文本文件中很容易,如下所示:

 $file = 'data/preciousdata.txt';
 // The new data to add to the file
 $put = $somedescription .": ". $somevalue;
 // Write the contents to the file, 
 file_put_contents($file, $put, FILE_APPEND | LOCK_EX);
Run Code Online (Sandbox Code Playgroud)

每次写入时都会有不同的描述和价值.

现在我想读取数据,所以你会得到这个文件:

 $myFile = "data/preciousdata.txt";
 $lines = file($myFile);//file in to an array
Run Code Online (Sandbox Code Playgroud)

可以说我只是在文本文件中写了"color:blue"和"taste:spicy".我不知道它们是哪一行,我想要检索"color:"描述的值.

编辑 我应该让PHP"搜索"文件,返回包含"描述"的行号,然后将该行放在一个字符串中并删除":"的所有内容?

php

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

php ×2

parsing ×1

yaml ×1