php - fscanf() / sscanf() - Match variable length Whitespace? -
i use sscanf() or (preferably) fscanf() scan /proc/meminfo , return memtotal:
memtotal: 1027156 kb memfree: 774596 kb buffers: 23816 kb cached: 198300 kb since number of spaces between memtotal: , actual number varies, i'm wondering if sscanf() smart enough parse like:
sscanf($line, "memtotal:\s+%d"); will padding , alignment specifiers of sprintf() work sscanf() well?
i try out on own, don't have dev / linux environment available atm.
yes, sscanf smart enough parse arbitrary number of spaces between. don't need specify in special way. do
sscanf($line, '%s%d'); and you'll
array ( [0] => memtotal: [1] => 1027156 ) unfortunately, php manual isn't complete can use format string, since it's based on unix command, can @ other documentations find options have:
- http://docs.roxen.com/pike/7.0/tutorial/strings/sscanf.xml
- http://www.cplusplus.com/reference/cstdio/scanf/
- https://en.wikipedia.org/wiki/scanf_format_string
it's bit fiddly them working though.
Comments
Post a Comment