Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $command = explode(" ", "!convert 25 psi bar");
- if(count($command) < 4 || !is_numeric($command[1])) {
- echo "usage";
- return;
- }
- //MEASUREMENTS =>
- $Pressure = [
- "bar" => [
- "bar" => 1,
- "kg" => 1.02,
- "psi" => 14.5,
- ],
- "kg" => [
- "bar" => 0.98,
- "kg" => 1,
- "psi" => 14.2,
- ],
- "psi" => [
- "bar" => 0.069,
- "kg" => 0.0703,
- "psi" => 1,
- ],
- ];
- if(!(in_array($command[2], array_keys($Pressure)) && in_array($command[3], array_keys($Pressure)))) {
- echo "usage";
- return;
- }
- print "{$command[1]} {$command[2]} = " . ($command[1] * $Pressure[$command[2]][$command[3]]) . " {$command[3]}\n";
- //
- $command = explode(" ", "!convert 1 miles millimeters");
- if(count($command) < 4 || !is_numeric($command[1])) {
- echo "usage";
- return;
- }
- $Length = [
- "millimeters" => 1,
- "centimeters" => .1,
- "miles" => 0.0000006214,
- "inches" => 0.0393701,
- "meters" => 0.001,
- "kilometers" => 0.000001,
- "feet" => 0.00328084,
- "yards" => 0.00109361,
- ];
- if(!(in_array($command[2], array_keys($Length)) && in_array($command[3], array_keys($Length)))) {
- echo "usage\n";
- return;
- }
- print "{$command[1]} {$command[2]} = " . ($Length[$command[3]] / $Length[$command[2]] * $command[1]) . " {$command[3]}\n";
- //
- $command = explode(" ", "!convert 1 grams oz");
- if(count($command) < 4 || !is_numeric($command[1])) {
- echo "usage";
- return;
- }
- $Weight = [
- "grams" => 1,
- "oz" => 0.035274,
- "kilograms" => 0.001,
- "pounds" => 0.00220462,
- "metrictons" => 0.000001,
- "tons" => 0.0000010231,
- ];
- if(!(in_array($command[2], array_keys($Weight)) && in_array($command[3], array_keys($Weight)))) {
- echo "usage\n";
- return;
- }
- print "{$command[1]} {$command[2]} = " . ($Weight[$command[3]] / $Weight[$command[2]] * $command[1]) . " {$command[3]}\n";
- //
- $command = explode(" ", "!convert 1 milliliters ounces");
- if(count($command) < 4 || !is_numeric($command[1])) {
- echo "usage";
- return;
- }
- $Volume = [
- "milliliters" => 1,
- "ounces" => 0.033814,
- "quarts" => 0.00105669,
- "pints" => 0.00211338,
- "cups" => 0.00422675,
- "liters" => 0.001,
- "gallons" => 0.00026417,
- ];
- if(!(in_array($command[2], array_keys($Volume)) && in_array($command[3], array_keys($Volume)))) {
- echo "usage\n";
- return;
- }
- print "{$command[1]} {$command[2]} = " . ($Volume[$command[3]] / $Volume[$command[2]] * $command[1]) . " {$command[3]}\n";
- // BASE: base_convert
- $command = explode(" ", "!convert 11111111 bin hdeci");
- if(count($command) < 4 || !is_numeric($command[1])) {
- echo "usage";
- return;
- }
- $bases = [
- "hdeci" => 16,
- "dec" => 10,
- "oct" => 8,
- "bin" => 2,
- ];
- if(!(in_array($command[2], array_keys($bases)) && in_array($command[3], array_keys($bases)))) {
- echo "usage\n";
- return;
- }
- print "{$command[1]} in {$command[2]} = " . strtoupper(base_convert($command[1], $bases[$command[2]], $bases[$command[3]])) . " in {$command[3]}\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement