public function testFunction() { $this->assertEquals(' foo', leftpad('foo', 5)); $this->assertEquals('foobar', leftpad('foobar', 6)); $this->assertEquals('foobar', leftpad('foobar', 3)); $this->assertEquals('01', leftpad(1, 2, 0)); $this->assertEquals('-1', leftpad(1, 2, '-')); }
function pad($bin, $type = 0, $len = 0) { if ($type == 0) { $bin = $bin . "1"; $buff = strlen($bin) % 512; if ($buff != 448) { while (strlen($bin) % 512 != 448) { $bin = $bin . "0"; } } } elseif ($type == 1) { $bLen = leftpad(decbin($len), 64); $bin .= implode('', array_reverse(str_split($bLen, 8))); } return $bin; }