在PHP中使用sscanf导致错误结果

在PHP中使用sscanf导致错误结果,php,scanf,Php,Scanf,这是我正在运行的代码,结果应该是错误的 $results = sscanf("Sept 30th, 2014 ", "%s , %s, %d"); print_r($results); 但我得到的结果 ( [0] => Sept [1] => [2] => ) 结果应该是: ( [0] => Sept [1] => 30th [2] => 2014 ) 我怎么了?我如何修复它?这是关于逗号的,请将其从格式中删除: $re

这是我正在运行的代码,结果应该是错误的

$results = sscanf("Sept 30th, 2014 ", "%s , %s, %d");
print_r($results);
但我得到的结果

(
   [0] => Sept
   [1] => 
   [2] => 
)
结果应该是:

(
  [0] => Sept
  [1] => 30th
  [2] => 2014
)

我怎么了?我如何修复它?

这是关于逗号的,请将其从格式中删除:

$results = sscanf("Sept 30th, 2014 ", "%s %s %d");
这应返回:

Array
(
    [0] => Sept
    [1] => 30th,
    [2] => 2014
)

如果不希望逗号出现在结果中,可以使用
str\u replace
或其他方法将其从第一个数组中删除,尝试以下操作:

$results = sscanf(" Sept 30th, 2014 ", "%s  %s %d");
$results[1]=str_replace(',','',$results[1]);// this can be done for entire array also.
print_r($results);
$results = sscanf("Sept 30th, 2014 ", "%s %s %d");
$results = str_replace(',', '',$results);
print_r($results);

如果不需要逗号,请尝试以下操作:

$results = sscanf("Sept 30th, 2014 ", "%s %s %d");
$results = str_replace(',', '',$results);
print_r($results);
输出:
数组([0]=>Sept[1]=>30th[2]=>2014)

如果没有逗号,您可以像

$results = sscanf("Sept 30th, 2014 ", "%s %[^','], %d");
print_r($results);
给你

Array ( [0] => Sept [1] => 30th [2] => 2014 )
您可以在模式本身中省略逗号