我有这个文件:
[playlist]
numberofentries=4
File1=http://108.61.73.119:8128
Title1=(#1 - 266/1000) 181.FM - POWER 181 -=[: The Hitz Channel :]=- www.181.fm
Length1=-1
File2=http://108.61.73.118:8128
Title2=(#2 - 318/1000) 181.FM - POWER 181 -=[: The Hitz Channel :]=- www.181.fm
Length2=-1
File3=http://108.61.73.117:8128
Title3=(#3 - 401/1000) 181.FM - POWER 181 -=[: The Hitz Channel :]=- www.181.fm
Length3=-1
File4=http://198.27.79.224:9770
Title4=(#4 - 27/50) 181.FM - POWER 181 -=[: The Hitz Channel :]=- www.181.fm
Length4=-1
Version=2
我想解析它并只获取文件和标题。问题是 parse_ini_file 给我虚假错误。我尝试了正常的方式,就像我会解析文本文件一样,但由于修剪太多,它变得很复杂。
有什么想法吗?
PHP:
$streams = parse_ini_file("tunein-station.pls", true);
print_r($streams);
错误:
PHP Warning: parse error in tunein-station.pls on line 4\n
最佳答案
尝试使用 INI_SCANNER_RAW
扫描仪,如下所示:
parse_ini_file('playlist.ini', true, INI_SCANNER_RAW);
这应该可以更好地处理带有空格和 []
且周围没有 "
的字符串。请参阅 parse_ini_file()
手册中的扫描仪模式。
关于php - 如何使用 PHP 解析 .pls 文件? parse_ini_file 有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18174908/