You want to replace the last comma and the rest of the comma, followed by any other character to the end of the line.
This can be formulated as a regular expression and this pattern can be replaced with preg_replace
with an empty string:
$until = preg_replace('/,[^,]*$/', '', $string);
This is a variant of mario answer , which works if there is no comma in the line.
source share