Choose a point in PHP sscanf?

This does not work:

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

While doing this:

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

Any suggestions really appreciated. Thank.

+3
source share
3 answers

You can use the base (negated) character class instead s, as in:

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

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

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

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

+2
source

Source: https://habr.com/ru/post/1729550/


All Articles