Last active
June 7, 2024 11:36
-
-
Save antom/661626 to your computer and use it in GitHub Desktop.
Returns a string list with the final instance of $glue found substituted with $last - eg. "a, b, c, d, e" -> "a, b, c, d and e" if glue is ', ' and $last is ' and '.
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
function str_list_ended($value, $glue = ', ', $last = ' and ') { | |
return preg_replace( | |
"/($glue)(?!.+$glue)/", | |
$last, | |
(is_array($value) ? implode($glue, $value) : $value) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment