Php搜索关键字并输出关键字所在的行


Php search keyword and output this line where keyword be

我想在大型文本内容中搜索关键字并输出此行。我的示例文本如下:

HSPICE模拟方法对所提出的基于RTD的纳米结构的巢列表进行验证使用上述表示方法的图像函数的候选者。

类别和主题描述符: C.5.4 [计算机系统实现]: VSLI 系统

一般条款:设计其他关键词和短语:VLSI,量化,颜色提取,彩色图像处理,共振

隧道二极管, 蜂窝神经网络

ACM 参考格式:

最后,我想通过搜索关键字"通用术语"来输出"通用术语:设计其他关键字和短语:VLSI,量化,颜色提取,彩色图像处理,共振-"。我怎样才能用PHP编码得到这个结果?对于全文,请将其$content,并且$key="一般条款";

你想使用正则表达式 - http://www.php.net/manual/en/function.preg-match.php

$search = 'General Terms:';
$pattern = '/'.$search.'(.)+/';
$content = 'HSPICE simulation methods for the nestlist of the proposed RTD-based nanoarchitecture in order to verify a candidate of image functions by using the afore-mentioned representation methods.
Categories and Subject Descriptors: C.5.4 [Computer System Implementation]: VSLI Systems
General Terms: Design Additional Key Words and Phrases: VLSI, quantization, color extraction, color image processing, resonant-
tunneling diode(s), cellular neural network';
preg_match($pattern, $content, $out);
$out[0] = str_replace($search, '', $out[0]);
print_r($out);
// Array ( [0] => Design Additional Key Words and Phrases: VLSI, quantization, color extraction, color image processing, resonant- [1] => )