更新时间:2023-11-14 14:36:04
试试下面的代码
$string = 'Dark Green = 11 = No = 20,
Light Blue = 12 = No = 20,
Lime Green = 13 = No = 20,
Sensei Gray = 14 = Yes = 0';
$string = explode(',',$string);
foreach($string as $row)
{
preg_match('/^(D+)s=s(d+)s=s(D+)s=s(d+)/', trim($row), $matches);
echo $matches[1];//Dark Green
echo $matches[2];//11
echo $matches[3];//No
echo $matches[4];//20
}
在循环中用于检查要搜索的单词
In the loop use to check the word to search
就这样
if($matches[1] == 'Dark Green')
{
echo $matches[1];
}
或
if($matches[2] == 11)
{
echo $matches[2];
}
(...)要获取文件中的文本,请尝试使用
(...) To get the text in the file try use
$string = file_get_contents('file.txt');