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:

it's bit fiddly them working though.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -