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

时间:2013-10-15 23:45:34

标签: php search data-analysis

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

针对基于RTD的nanoarchitecture的嵌套列表的HSPICE仿真方法以进行验证 通过使用上述表示方法的图像函数候选。

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

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

隧道二极管,细胞神经网络

ACM参考格式:

最后我想通过搜索关键词“一般术语”来输出“一般术语:设计附加关键词和短语:VLSI,量化,颜色提取,彩色图像处理,谐振 - ”。如何用PHP编写代码得到这个结果?对于整个文本,请使用$ content,$ key =“一般条款”;

1 个答案:

答案 0 :(得分:0)

您想使用正则表达式 - 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] => )