Author Topic: Checking a string for something.  (Read 1415 times)

If I had a long list of words in a global variable how would I check through that list for one word eg:

$words = "hi hai hello";
$a = "hello";

then it would check if $words has $a in it.

Worked it out.

Maybe not
« Last Edit: November 18, 2007, 11:16:07 AM by MrPickle »


strpos($words, $a, 0) will return -1 if it's not in there, or an integer of the first character if it is. HEnce, you can use this:

if(strpos($words, $a, 0) != -1)

(just so you know, the 0 parameter is a starting position... if you wanted to ignore any results before a certain point, you would make it a positive integer.)

This isn't working:

Code: [Select]
$Hello = "Hi Hai Hello Heya Hey";
%line = "Hello Hi Heya";
if(strpos(strlwr(getWord(%line,1)),strlwr($Hello),0)!=-1)

Code: [Select]
$Hello = "Hi Hai Hello Heya Hey";
%line = "Hello Hi Heya";
if(strstr(strlwr($Hello), strlwr(getWord(%line, 1))) != -1)


You must be the biggest thread-starter in this section of the forums.

You must be the biggest thread-starter in this section of the forums.

Yes I am, I always need help.

We all start somewhere though, right?

Yes.  Some start at the top, and some at the bottom.

 :cookieMonster:



Please lock this topic.