Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,990 questions

51,935 answers

573 users

How to check if a characters exist in a string with PHP

3 Answers

0 votes
$s = "php programming"; 
        
echo strpos($s, 'o') . "<br />";

if (strpos($s, 'x') === false) {
    echo "false" . "<br />";
}

if (strpos($s, 'x') !== false) {
    echo "exist";
}
else {
    echo "not exist";
}


    
/*
run:

6
false
not exist
         
*/

 



answered Jan 11, 2020 by avibootz
0 votes
$s = "php programming"; 
        
echo strstr($s, 'o') . "<br />";

if (strstr($s, 'x') === false) {
    echo "false" . "<br />";
}

if (strstr($s, 'w') !== false) {
    echo "exist";
}
else {
    echo "not exist";
}


    
/*
run:

ogramming
false
not exist
         
*/

 



answered Jan 12, 2020 by avibootz
0 votes
$s = "php programming"; 
        
echo stristr($s, 'G') . "<br />"; // Case-insensitive strstr

if (stristr($s, 'Z') === false) {
    echo "false" . "<br />";
}

if (stristr($s, 'L') !== false) {
    echo "exist";
}
else {
    echo "not exist";
}


    
/*
run:

gramming
false
not exist
         
*/

 



answered Jan 12, 2020 by avibootz

Related questions

2 answers 269 views
1 answer 161 views
161 views asked May 23, 2018 by avibootz
1 answer 192 views
192 views asked Jul 7, 2014 by avibootz
1 answer 157 views
1 answer 162 views
...