从文件中提取特定单词


Take a specific word from a file

使用PHP,我尝试执行以下任务:

1) 读取输入文件:

// some lines
request_context.base_path: /~test1/test2/web/ 
// some lines

2) 获得以下输出:

/~test1/test2/web/ 

这是我的代码,但它不起作用
有什么想法吗?谢谢

<?php
$lines = file('app/parameter.conf');
$l_count = count($lines);
for($x = 0; $x< $l_count; $x++)
{
    if (strpos($lines[$x],'request_context.base_path:') !== false) {
        preg_match('(request_context.base_path:)('s.*)', $lines[$x], $matches);
        echo $matches[1];
    }
}
?>

为什么这么大惊小怪?

preg_match('/request_context.base_path: (.*)/', $lines[$x], $matches);