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.
精彩评论