I have a variable $var="this is a long string..............some thing more"; I have to search if this variable contains the keyword "long" is present or not. Could u help me.
Thanks in advance
Original Title[solved]
Moderator: General Moderators
-
sumanbangladesh
- Forum Newbie
- Posts: 5
- Joined: Tue Sep 18, 2007 2:41 am
Original Title[solved]
Last edited by sumanbangladesh on Tue Sep 18, 2007 9:55 pm, edited 1 time in total.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
The normal method for looking for something like this (assuming you want 'long' as a word, not within another word) is to use the command preg_match. Pattern syntaxes can get quite complicated but it worth your while to read Preg Pattern Syntax and get to terms with how things work rather than just giving you a solution without you understanding how it works.
Another solution if you don't care about 'long' being within another word is to use stristr. It will find it if part of another word, followed by ',', '.' or space etc.
Another solution if you don't care about 'long' being within another word is to use stristr. It will find it if part of another word, followed by ',', '.' or space etc.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Here is quite a nifty little method:
http://uk.php.net/manual/en/function.stristr.php
Code: Select all
$test="Hello this is a test";
if(stristr($test, 'this') === FALSE)
{
echo 'no match';
}
else
{
echo "match found";
}-
sumanbangladesh
- Forum Newbie
- Posts: 5
- Joined: Tue Sep 18, 2007 2:41 am
Search Keyword is solved
Thank you.