【发布时间】:2015-08-06 15:59:12
【问题描述】:
我有一个包含以下内容的文件:
test:fOwimWPu0eSaNR8
test2:vogAqsfXpKzCfGr
我希望能够在文件中搜索 test 并将 : 之后的字符串设置为变量,以便可以显示、使用等。
这是我目前在文件中查找“测试”的代码。
$file = 'file.txt';
$string = 'test';
$searchFile = file_get_contents($file);
if (preg_match('/\\b'.$string.'\\b/', $searchFile)) {
echo 'true';
// Find String
} else {
echo 'false';
}
我该怎么做呢?
【问题讨论】:
标签: php regex file preg-match file-get-contents