I have a script that I am running against a set of servers to pull hardware data off them using openwsman. This is in an attempt to keep track of changes in a very open environment as well as update a mysql db eventually to keep an inventory record. The issue is that preg_replace is adding '1''s at the beginning and end of each value in the array. These steps are rather unusual I'm sure, so I'll explain what each does and provide the output at the end.
$memsize = shell_exec("wsman enumerate http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/root/dcim/DCIM_MemoryView -h $ipaddress -V -v -c dummy.cert -P 443 -u $user -p $pass -j utf-8 -y basic | grep 'Size'");
$memsize = trim($memsize); #Removes excess spaces at beginning and end of the output.
$memsize = str_replace(' ',',',$memsize); #Replaces spaces between values with a comma.
$memsize = explode(',',$memsize); #Converts the values pulled into an array with comma as the delimiter
$memsizepreg = preg_replace("/[^0-9]/","",$memsize); #Deletes all non-number characters.
$memsizesum = array_sum($memsizepreg); #Gets a sum of all the detected DIMMs.
echo $memsize[0];
echo "<br>";
echo $memsize[1];
echo "<br>";
echo $memsize[2];
echo "<br>";
echo $memsize[3];
echo "<br>";
echo var_dump($memsize);
echo "<br>";
echo $memsizepreg[0];
echo "<br>";
echo $memsizepreg[1];
echo "<br>";
echo $memsizepreg[2];
echo "<br>";
echo $memsizepreg[3];
echo "<br>";
echo var_dump($memsizepreg);
echo "<br>";
echo $memsizesum;
In addition, if I delete the preg_replace, the array_sum gets a blank. I outputted the variables memsize, memsizepreg and memsize sum variables just to ensure that the pulled data was accurate and whatever the preg_replace is doing, is causing a 1 to be added to the beginning and end of the variable.
Output:
2048
2048
2048
2048
array(4) { [0]=> string(24) "2048 " [1]=> string(24) "2048 " [2]=> string(24) "2048 " [3]=> string(23) "2048" }
120481
120481
120481
120481
array(4) { [0]=> string(6) "120481" [1]=> string(6) "120481" [2]=> string(6) "120481" [3]=> string(6) "120481" }
481924