3

Possible Duplicate:
How to make strpos non case sensitive

I am testing to see if a string contains the text "People Who Like". Well, the code works great! Except it is case-sensitive. What can I do to prevent this?

If the string is "people who like to run" it returns false If the string is "People who like to run" it returns true

I want it to not be case sensitive.

Code:

<?php

$string = "People who like to run";

if (strrpos($string, 'People who like') === false) {
    echo "False";
}
else {
    echo "True";
}
Community
  • 1
  • 1
Matt
  • 163
  • 3
  • 10

3 Answers3

12

See strripos, the case insensitive-version of strrpos.

nice ass
  • 16,471
  • 7
  • 50
  • 89
9

use strripos instead

OR

use strtolower on the string before testing it

$string = "People who like to run";

if (strrpos(strtolower($string), strtolower('People who like')) === false) {
    echo "False";
}
else {
    echo "True";
}
Ethan
  • 2,754
  • 1
  • 21
  • 34
4

Use strripos for case-insensitive match

Yoni Hassin
  • 584
  • 1
  • 5
  • 17