Jump to content

Help with stripos


crusty76

Recommended Posts

I thought it would be simple but it isn't.  I have the code (example)

 

<?PHP

$search="a";

$total = "aNbh jK ";

if( stripos(" " .$total,$search,0) == TRUE) {

echo"found";

} else {

echo "Not found";

}

?>

 

The result is 'Not found'. It should be found surely?

If $search ="n" it works.!

What am I doing wrong please.

Crusty

 

Link to comment
https://forums.phpfreaks.com/topic/200894-help-with-stripos/
Share on other sites

Thanks for the suggestion.

Tried that and unfortunately, it doesn't work. Seems it wont find a character which is the first character in '$haystack' In my case $total.

 

Any other thoughts please. I'm getting frustrated with thus simple(?) problem.

Thanks

Crusty

 

<?PHP

$search="a";

$total = "aNbh jK ";

if( stripos(" " .$total,$search,0) === TRUE) {

echo"found";

} else {

echo "Not found";

}

?>

Link to comment
https://forums.phpfreaks.com/topic/200894-help-with-stripos/#findComment-1054162
Share on other sites

quote from the manual...

Warning

This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

 

http://php.net/manual/en/function.stripos.php

 

might try using >=0  rather than 'true/false'

 

Link to comment
https://forums.phpfreaks.com/topic/200894-help-with-stripos/#findComment-1054188
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.