Alex Rivera | Logout

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

Asked 2009-07-15T13:27:42.310
11

I want to remove everything (including the comma) from the first comma of a string in PHP.

For example,

$print = "50 days,7 hours";

should become

50 days
Edit
Report

1 Answer

5

You can also use current function:

$firstpart = current(explode(',', $print)); // will return current item in array, by default first

Also other functions from this family:

$nextpart = next(explode(',', $print)); // will return next item in array

$lastpart = end(explode(',', $print)); // will return last item in array
answered 2013-04-29T12:52:48.690

Your Answer