remove everything after first comma from string in php

后端 未结 5 2070
闹比i
闹比i 2020-12-31 21:13

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

$print=\"50 days,7 hours\";

should become \"50

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-31 21:47

    You could use a regular expression, but if it's always going to be a single pairing with a comma, I'd just do this:

    
    $printArray = explode(",", $print);
    $print = $printArray[0];
    

提交回复
热议问题