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

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,088 questions

40,774 answers

573 users

How to check if a string contains a specific word (text) in PHP

Learn & Practice SQL


141 views
asked Feb 6, 2017 by avibootz
edited Feb 6, 2017 by avibootz

3 Answers

0 votes
$s = 'PHP HTML JavaScript';
 
if (strpos($s, 'PHP') !== false) 
    echo 'contains';
else
    echo 'not contains';


  
/*
run:
   
contains
    
*/

 





answered Feb 6, 2017 by avibootz
0 votes
$s = 'PHP HTML JavaScript';
 
if (preg_match('/PHP/',$s))
    echo 'contains';
else
    echo 'not contains';


  
/*
run:
   
contains
    
*/

 





answered Feb 6, 2017 by avibootz
0 votes
$s = 'PHP HTML JavaScript';
 
if (strstr($s, "PHP"))
    echo 'contains';
else
    echo 'not contains';


  
/*
run:
   
contains
    
*/

 





answered Feb 6, 2017 by avibootz

Related questions

...