Skip to content
PHP Logo

What PHP function can be used to manipulate a string to remove everything after a comma, including the comma itself?

To remove everything after a comma in a string, including the comma itself, you can use the PHP `explode()` function to split the string into an array based on the comma, and then access the first element of the array which contains the part of the string before the comma. This effectively removes everything after the comma. You can then use the `implode()` function to join the array elements back into a string if needed.

php
$string = "Hello, world!";
$parts = explode(',', $string);
$finalString = $parts[0];
echo $finalString; // Output: Hello