在 PHP 中使用 sscanf 导致错误结果 [英] Wrong Results by Using sscanf in PHP

查看:39
本文介绍了在 PHP 中使用 sscanf 导致错误结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我正在运行的代码 结果是错误的!

Here is the Code i'm running Results are wrong as they supposed to be!

$results = sscanf("Sept 30th, 2014 ", "%s , %s, %d");
print_r($results);

但是我得到的结果

(
   [0] => Sept
   [1] => 
   [2] => 
)

结果应该是:

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

我怎么了?我该如何解决?

What's Wrong am i doing ? how can i fix that ?

推荐答案

without str_replace 对于逗号,你可以这样做

without str_replace for commas, you can do it like

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

给你

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

您可以在模式本身中省略逗号.

you can omit comma in the pattern itself.

这篇关于在 PHP 中使用 sscanf 导致错误结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆