我的字符串格式如此'2014-07-11-4-8'。 '2014-07-11'部分是日期,'4'是整数,'8'是整数。如何使用PHP将原始字符串拆分为这3个变量?
答案 0 :(得分:3)
尝试使用正则表达式:
$string = '2014-07-11-4-8';
preg_match("/(\d{4}-\d{2}-\d{2})-(\d+)-(\d+)/", $string, $matches);
print_r($matches);
$date = $matches[1];
$int1 = $matches[2];
$int2 = $matches[3];
答案 1 :(得分:-1)
$date = "2014-07-11-4-8";
$array = explode("-", $date);
然后你可以访问数组变量
中的每个元素