Search
 
SCRIPT & CODE EXAMPLE
 

PHP

check if string contains substring

Like this:

if (str.indexOf("Yes") >= 0)
...or you can use the tilde operator:

if (~str.indexOf("Yes"))
This works because indexOf() returns -1 if the string wasn't found at all.

Note that this is case-sensitive.
If you want a case-insensitive search, you can write

if (str.toLowerCase().indexOf("yes") >= 0)
Or:

if (/yes/i.test(str))
Comment

str_contains — Determine if a string contains a given substring

<?php
if (str_contains('abc', '')) {
    echo "Checking the existence of the empty string will always return true";
}
?>
Comment

string contains a substring

const string = "foo";
const substring = "oo";

console.log(string.includes(substring)); // true
Comment

PREVIOUS NEXT
Code Example
Php :: laravel package development 
Php :: php session 
Php :: php $this 
Php :: pagination javascript php 
Php :: laravel project composer [ErrorException] Undefined index: name 
Php :: array session 
Php :: laravel package console command 
Php :: Best testing tools for php 
Php :: query builder codeigniter 
Php :: laravel with select 
Php :: tag php 
Php :: laravel collection 
Php :: how to run php in javascript 
Php :: laravel available router methods 
Php :: php reverse string 
Php :: laravel 8 login logout 
Php :: return last inserted id mysql opencart 
Php :: laravel Call to a member function validate() on array 
Php :: csv import in laravel 
Php :: codeigniter ellipsis in php read more text 
Php :: php sdk paytm 
Php :: register style wordpress 
Php :: count vs sizeof php 
Php :: check not empty in laravel blade 
Php :: php mysql text mark question 
Php :: text short in laravel 
Php :: joomla k2 api 
Php :: filter from taggable laravel 
Php :: search and pagination in ci4 
Php :: Right triangle start pattern of star 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =