且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP 搜索和回显特定文本

更新时间: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');