-1

I want to check if the string is present in another string

even if the string is in this format: are, ARE, Are, aRe, arE

$str = "how aRe you doing";
if (strpos($str,'are') !== false) 
{
    echo 'true';
}
DeathRs
  • 980
  • 13
  • 20
  • possible duplicate of [How to make strpos case insensitive](http://stackoverflow.com/questions/6795383/how-to-make-strpos-case-insensitive) – Rizier123 Feb 22 '15 at 08:53
  • @Rizier123 Thanks!, i had to ask this question because i was unsuccessful in searching the solution on the web. maybe due to lack of keywords in my mind. – DeathRs Feb 22 '15 at 09:00
  • FYI: If you didn't knew it already you can also search stuff on SO here: http://stackoverflow.com/search?q= Also just use keywords if you search stuff e.g. `php strpos case insensitive` – Rizier123 Feb 22 '15 at 09:02

3 Answers3

1

Use stripos() instead of strpos().

int stripos ( string $main_string , string $substring [, int $offset = 0 ] )

Rizier123
  • 56,111
  • 16
  • 85
  • 130
tourniquet_grab
  • 662
  • 7
  • 14
1

You can use strpos function with strtolower function

$str = "how are you doing";
$ndl = 'ArE';
if (strpos(strtolower($str),strtolower($ndl))) {
    echo "true";
}else{
    echo "false";
}
0
$str = "how aRe you doing";
if (strpos(strtolower($str),'are') !== false) 
{
    echo 'true';
}
JBA
  • 2,827
  • 1
  • 19
  • 33