Last active
March 13, 2018 23:53
-
-
Save quickshiftin/9f080c7323a90a459091bf313ea4d915 to your computer and use it in GitHub Desktop.
substr_to - find substring up to given character in php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is such a common thing, I decided to put it in a gist so I don't have to keep reinventing it every time LOL. | |
*/ | |
function substr_to($haystack, $needle) { | |
$iPos = strpos($haystack, $needle); | |
if($iPos === false) { | |
return false; | |
} | |
return substr($haystack, 0, $iPos); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment