Posted By

william0760 on 09/24/11


Tagged

String


Versions (?)

String Contains


 / Published in: PHP
 

startsWith, endsWith, Contains

  1. function str_startsWith($haystack, $needle) {
  2. return strpos($haystack, $needle) === 0;
  3. }
  4.  
  5. function str_endsWith($haystack, $needle){
  6. return strrpos($haystack, $needle) === strlen($haystack)-strlen($needle);
  7. }
  8.  
  9. function str_contains($haystack, $needle) {
  10. return strpos($haystack, $needle) !== false;
  11. }

Report this snippet  

You need to login to post a comment.