-1

Consider:

$a = 'How are you? @android_ar';

if ($a contains '@android_ar')
    echo 'true';

Suppose I have the code above, what is the correct way to write the statement if ($a contains '@android_ar')?

Note:

The mention (@android_ar) its change every time. So we can change it every time and not fixed

  • 1
    possible duplicate of [Check if string contains specific words?](http://stackoverflow.com/questions/4366730/check-if-string-contains-specific-words) – Daniel Jul 26 '15 at 06:00

2 Answers2

1

Use strpos($a, '@android_ar') !== false.

user4759923
  • 531
  • 3
  • 12
1

as with all php code there are lots of ways to do this and everyone has their own idea, but check out strstr()

e.g.

$test = '@android_ar';
if (strtr($a,$test))
    echo 'true';

see also:
strpos() - Find the position of the first occurrence of a substring in a string
stripos() - Find the position of the first occurrence of a case-insensitive substring in a string
strrpos() - Find the position of the last occurrence of a substring in a string
strripos() - Find the position of the last occurrence of a case-insensitive substring in a string
strstr() - Find the first occurrence of a string
strpbrk() - Search a string for any of a set of characters
substr() - Return part of a string
preg_match() - Perform a regular expression match

Wee Zel
  • 1,294
  • 9
  • 11