2013-10-15 161 views
0

我想在大型文本內容中搜索關鍵字並輸出此行。 我的示例文本如下:爲了PHP搜索關鍵字和輸出此行關鍵字是

HSPICE模擬方法的所提出的基於RTD-納米架構的nestlist通過使用前面提到的表示方法來驗證 一個的圖像的功能的候選。

分類和主題描述:C.5.4 [計算機系統實現]:VSLI系統

一般條款:設計 附加關鍵詞和短語:VLSI,量化,色彩提取,彩色圖像處理,resonant-

隧道二極管(一個或多個),細胞神經網絡

ACM參考格式:

最後,我想只輸出「一般術語:設計附加關鍵詞和短語:VLSI,量化,顏色提取,彩色圖像處理,諧振 - 「通過搜索關鍵詞」一般術語「。我如何在PHP中獲得這個結果?對於整個文本,讓它爲$ content,並且$ key =「一般條款」;

+0

http://stackoverflow.com/questions/9721952/search-string-and-return-line-php – Scuzzy

回答

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] =>)