Remove everything from the first occurrence of a character to the end of a string in PHP

Here’s one way:

$print = preg_replace('/^([^,]*).*$/', '$1', $print);

Another:

list($print) = explode(',', $print);

Or:

$print = explode(',', $print)[0];

Leave a Comment