Skip to content

Instantly share code, notes, and snippets.

@graymic
Created March 24, 2014 14:38
Show Gist options
  • Save graymic/a5074ff85d50d3585fde to your computer and use it in GitHub Desktop.
Save graymic/a5074ff85d50d3585fde to your computer and use it in GitHub Desktop.
Allows for multiple delimiters in a string pos function.
$str_pos_array = function ($haystack, $needles=[], $offset=0) {
$characters = [];
foreach($needles as $needle) {
$res = strpos($haystack, $needle, $offset);
if ($res !== false) {
$characters[$needle] = $res;
}
}
if(empty($characters)) {
return false;
}
return min($characters);
};
@graymic
Copy link
Author

graymic commented Mar 24, 2014

Example:

$url = substr($url, 0, $strposarray($url, array("&", "?")));

Will strip the url after the & and ? delimiters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment