开发者

Escape the dot in PHP sscanf?

This doesn't work:

list($value) = sscanf('foo.bar','%s.bar');
echo $value; //foo.bar

While this does:

list($value开发者_如何转开发) = sscanf('foo bar','%s bar');
echo $value; //foo

Any suggestions are really appreciated. Thanks.


You can use a basic (negated) character class instead of s as in:

list($value) = sscanf('foo.bar','%[^.].bar');
echo $value; //foo


you can use explode instead of sscanf() for what you want to do.

$str = "foo.bar";
list($value1,$value2) = explode(".",$str);
print $value1;


I think it by design. It is trivial to use preg_match here, to be honest.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜