MyBB Community Forums

Full Version: find word in a variable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Peace,
Its me again Blush

Look at the following codes
$publishperm = strpos($mybb->settings['fbconnect8'],"publish_stream");
if($publishperm)
{
	echo "Pass";
}
else
{
	echo "Fail";
}
I want certain codes to run only if the user has entered "publish_stream" (w/o quotes) in setting fbconnect8. He may enter other things as well separated by commas.

If a user inserts "lol,publish_stream" in fbconnect8, i get "Pass". If he enters only "publish_stream", i get fail. I guess this is because the count begins at 0. How would i be able to get something like this done in some another way?
if(preg_match("/publish_stream/", $mybb->settings['fbconnect8'])) {
echo "Pass";
}
else {
echo "Fail";
}
strpos returns false if it doesn't find it

since 0 and false are both false (as if and == view it), you have to use === (or !==) to compare

if($publishperm !== false) { echo "pass"; }

(2011-01-12, 03:59 PM)Jammerx2 Wrote: [ -> ]
if(preg_match("/publish_stream/", $mybb->settings['fbconnect8'])) {
echo "Pass";
}
else {
echo "Fail";
}
Thanks a lot. It worked Smile

(2011-01-12, 04:02 PM)frostschutz Wrote: [ -> ]strpos returns false if it doesn't find it

since 0 and false are both false (as if and == view it), you have to use === (or !==) to compare

if($publishperm !== false) { echo "pass"; }
I'll experiment on this later. Thanks Smile
(2011-01-12, 03:59 PM)Jammerx2 Wrote: [ -> ]
if(preg_match("/publish_stream/", $mybb->settings['fbconnect8'])) {
echo "Pass";
}
else {
echo "Fail";
}

preg_match is slower than strpos so you better use strpos if you can. There's no point on using a regular expression if you're not making use of it - you're just doing exactly what you could do with strpos.

if (strpos($string, $findwhat) === false) echo "fail";
else echo "success";
if($publishperm !== false) { echo "pass"; }

This code seems to be working perfectly. I'll be using this one then Smile

Thanks to everyone who helped me Smile