Page 1 of 1

Regular Expression Help Needed! Quite help I guess :/

Posted: Tue Oct 03, 2006 10:02 am
by kaisellgren
Hi,
Resources which are restricted to use by University faculty, staff, and students only can be found at the Encoded Text Services website. This site is made possible in part by a generous equipment grant from Sun MicroSystems Inc.
I have a $search that is now set to "site". I want it to preg_match return the whole line matching that search word.

preg_match("/.*$search.*/i",$text,$return);
echo $return[0];

But that returns the whole text, not just the line: This site is made possible in part by a generous equipment grant from Sun MicroSystems Inc.

I want to get the whole sentence where the search word is written in. Possible? Please help!

Posted: Tue Oct 03, 2006 10:42 am
by Burrito
Moved to regex.

Posted: Tue Oct 03, 2006 10:44 am
by Burrito
try something like this:

Code: Select all

$pattern = "/\.(.*?$search.*?)\./";