Zaki Mustafa
Zaki Mustafa

Reputation: 147

removing Case sensitivity and substring check in php

I want to find out whether the input string is a substring of another string or not , is there any function that do so ignoring case sensitivity? The substring check should be done ignoring case sensitivity. Please tell me about any such function

Upvotes: 1

Views: 300

Answers (2)

Thamilhan
Thamilhan

Reputation: 13303

You can also use stripos

Find the position of the first occurrence of a case-insensitive substring in a string

if(stripos("This is a test string","A Test")!==FALSE)
{
    echo "Yes";
}

Check this note for stristr from manual:

Note: If you only want to determine if a particular needle occurs within haystack, use the faster and less memory intensive function strpos() instead.

Upvotes: 1

Hanky Panky
Hanky Panky

Reputation: 46900

Use stristr

Returns the matched substring. If needle is not found, returns FALSE.

if(stristr("Hello","hello world")!==FALSE)
{
  // Yes needle is a part of haystack
}

Upvotes: 2

Related Questions