php sscanf removing ":" from "1.1.1.1:22" string
Hi group,
I'm fighting with sscanf again. This is the script Code:
#!/usr/bin/php Code:
filter-1.php LOG-18Oct2016-Tuesday Thanks for your time. |
Try this...
Code:
$N = sscanf( "1.1.1.1:22 junk" , "%[^':']:%s", $IP, $Port ); |
Quote:
Does the "%[^:]" define a string? What if I wanted an integer? Seems "%d:%s " works but "%[^:]d:%s" does not! Well, will wonders ever end? Thanks for the fix. |
"%[^:]:%s" The [^:] means match everything from the beginning of the line except for the : which is assigned to $IP. I not a regular expression expert by any means but it is all about text matching so as far as I know it will default to text. The :%s will match everything after the : and assign it to $Port. It does work if it is a %d instead of a %s.
|
Quote:
|
Quote:
https://manned.org/scanf.3 Code:
[ Matches a nonempty sequence of characters from the specified set |
@OP You should accept the fact that 'sscanf' isn't a universal lexical parser. Use it when possible, otherwise use other tools like function 'explode'.
|
Quote:
Sscanf works when you can figure out the secret hand shakes. Thanks for your time. |
All times are GMT -5. The time now is 02:04 AM. |