- floor: documentation ( source)
- preg_split: documentation ( source)
<?php
$in = "0 0 0 0 0.5230792 0 0 0 0.4769208 0
0 0
";
$data = preg_split("/[\s\n]/",$in);
$count = count($in);
$length = 1000;
$size = $length/$count;
$height = 100;
print "<svg width='$length' height='$height'>";
$x = 0;
foreach ($data as $line) {
$inte = floor($line*255);
print "<rect x='$x' y='0' width='$size' height='$height' style='fill:rgb($inte,$inte,$inte);stroke-width:1;stroke:white' />";
$x = $x+$size;
}
print "</svg>";
?>