什么是完成以下任务的最佳方法.
我有这种格式的字符串:
$s1 = "name1|type1"; //(pipe is the separator) $s2 = "name2|type2"; $s3 = "name3"; //(in some of them type can be missing)
假设nameN / typeN是字符串,它们不能包含管道.
$temp = explode('|',$s1); $name = $temp[0]; $type = ( isset($temp[1]) ? $temp[1] : '' );
有没有更容易(更聪明,更快)的方式,而不必做isset($temp [1])或count($temp).
谢谢!
list($name,$type) = explode('|',s1.'|');