Frage

I would like to search for a keyword in a large text content and output this line. My example text are as follow:

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

ACM Reference Format:

And finally I want to just output "general terms: Design Additional Key Words and Phrases: VLSI, quantization, color extraction, color image processing, resonant-" by searching key word "general terms". How Can I code in PHP get this result? For whole text let it be $content, and $key="General Terms";

War es hilfreich?

Lösung

You want to use regex - 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] => )
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top