Gordon Stewart wrote:
> 
> 
> Hello...
> 
> I'm wondering - Is there a way to combine two preg matches into one ?
> 
> basically, I've got a search system up & running now.. However if a
> person puts in certain words/phrases (shortened version of full word),
> I want it to search that word/phrase.. *AND* the full-word in one
> step / command...
> 
> EG :- (titfw = short version of "this is the full word"
> 
> $g=0;
> if(preg_match("/titfw/i",$line)){$g=1;}
> if(preg_match("/This is the full word/i",$line)){$g=1;}
> 
> if($g>0){
> echo "FOUND MATCHING LINE\n";
> Do other stuff .........
> }
> if($g<1){
> ignore line - Resume loop ...
> }
> 
> I'll rather do :-
> 
> if(preg_match("/SPECIAL TRICK TO GET BOTH WORDS OR PHRASES/i",$line)){
> echo "FOUND MATCHING LINE\n";
> Do other stuff .........
> }
> 
> Or is my top example a good way ?
> 
> (if the person doesnt put a search term in - that matches something I
> want - It just performs a regular search - Instead of the 2-word
> search...) - I've got a way to do that with only a few extra lines...
> - Just need help with above....

if(preg_match("/(?:titfw|This is the full word)/i",$line)){
   blah;
}
The pipe "|" means "or".

Reply via email to