Posted By

iloveitaly on 05/26/09


Tagged

start with has prefix


Versions (?)

startsWith / hasPrefix


 / Published in: PHP
 

  1. function startsWith($check, $string) {
  2. if ($check === "" || $check === $string) {
  3. return true;
  4. } else {
  5. return (strpos($string, $check) === 0) ? true : false;
  6. }
  7. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Vordreller on May 27, 2009

Nice one.

Check this implementation here on Snipplr, which I wrote: startsWith()

And if you wanna do it with the end of a string, I don't think you can use strpos(), check this implementation, which is also written by me: endsWith()

Which is the exact reason I didn't use it for the startswith() function either.

You need to login to post a comment.