execute linux command and store the output in php array -


i making php website used monitor linux server, used linux commands memory usage (free) & (cat /proc/meminfo),for disk storage, network, users etc... can execute linux command php commands exec , shell_exec , back-tick, etc... how store output in php array ? , how move each element array string or int variable perform string or int functions on ?

i try ,

    // memort details array !!!     $last_line = exec('cat /proc/meminfo', $retval);    // return memory total    echo $retval[1];    echo "<br> <br>";     // move  memory total variable      $memory_total=$retval[0];     echo "<br> <br> memory total variable $memory_total <br><br> ";      implode($memory_total);       //this give me memory total in kb    echo  substr($memory_total,9);     echo "<br> <br>"; 

but want result in int variable , , if there better way that?

your life easy regular expressions.

<?php  // why cat in shell info 1 file? use right/easy function! $data = file_get_contents('/proc/meminfo');  // pcre save in many cases! preg_match_all("/^([^:]+):\s+([0-9]+)\s*([a-z]+)?$/umi",$data,$meminfo,preg_set_order);  // need here var_dump($meminfo); 

your question int , string common mistake not read section about types in php page. indicate read basic section manual many of questions data manipulation answered. php evaluate data types in accordance function used.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -