Regular Expression Help Needed! Quite help I guess :/

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Regular Expression Help Needed! Quite help I guess :/

Post 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!
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Moved to regex.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

try something like this:

Code: Select all

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