PHP: Does a string contain a word independent from upper or lower case writing?
Question by Guest | 2014-02-10 at 15:37
I would like to determine using an if-statement whether specific string is containing a specific word (thus another string). With this, the difficulty is that I do not know, whether the word is written in uppercase or lowercase letter. So, I need something like a case insensitive search.
Up to now, I am using the function strpos($str, $searchstr).
However, the problem using strpos is, that this function does not differ writings, so "ABC" and "abc" are treated as different strings, but they should be treated as equal.
Does someone have an idea what I can do?
Related Topics
PHP: Check Strings with Ctype-Functions for Character Classes
Article | 0 Comments
MySQL: Combine full text search with LIKE search for words with 3 letters
Tutorial | 2 Comments
PHP: Get first Digit of Number or String
Tutorial | 0 Comments
PHP: Current Date and Time
Tutorial | 0 Comments
HTACCESS: Simplify URL
Tutorial | 0 Comments
Online Uppercase - Lowercase Converter
Tool | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
Spontaneously, I have two solutions in mind.
On the one hand, you can use strtolower or strtoupper to change the whole string to the same writing before the comparison completely:
Or you can just use stripos:
The PHP-function stripos finds a string in another string independent from their writing (case insensitive).
Alternatively, of course, you can also use regular expressions. If you want, a search for the PHP-function preg_match will help you. But I think, stripos is sufficient in your case.
2014-02-10 at 20:24