Skip to content

Instantly share code, notes, and snippets.

@quickshiftin
Last active March 13, 2018 23:53
Show Gist options
  • Save quickshiftin/9f080c7323a90a459091bf313ea4d915 to your computer and use it in GitHub Desktop.
Save quickshiftin/9f080c7323a90a459091bf313ea4d915 to your computer and use it in GitHub Desktop.
substr_to - find substring up to given character in php
<?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