Posted By

satie83 on 07/18/12


php String substring contain

Versions (?)

Who likes this?

2 people have marked this snippet as a favorite


PHP - How to check if string contains substring PHP

 / Published in: PHP


Once in a while we need to check whether a string contains substring, some other string or characters or a value. Checking for existence of a string (or substring) inside another string is easier than it might seem. The following article describes how to check for whether a string contains string in PHP, or simply said how to find string within string in PHP.

  1. $intPos = strpos($strHaystack,$strNeedle);
  3. if( $intPos === false ) {
  4. // string strNeedle NOT found in strHaystack
  5. } else {
  6. // string strNeedle found in strHaystack
  7. }

Report this snippet  

You need to login to post a comment.