fixing up the global functions and adding more conversions
This commit is contained in:
parent
bcf14cc604
commit
8312c5e54e
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
|--------------------------------------------------------------------------
|
||||
| Global Functions
|
||||
|--------------------------------------------------------------------------
|
||||
@ -94,25 +94,25 @@ if (! function_exists('is_serialized')) {
|
||||
}
|
||||
|
||||
$data = trim($data);
|
||||
if ('N;' === $data) {
|
||||
if ($data === 'N;') {
|
||||
return true;
|
||||
}
|
||||
if (strlen($data) < 4) {
|
||||
return false;
|
||||
}
|
||||
if (':' !== $data[1]) {
|
||||
if ($data[1] !== ':') {
|
||||
return false;
|
||||
}
|
||||
if ($strict) {
|
||||
$lastc = substr($data, -1);
|
||||
if (';' !== $lastc && '}' !== $lastc) {
|
||||
if ($lastc !== ';' && $lastc !== '}') {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$semicolon = strpos($data, ';');
|
||||
$brace = strpos($data, '}');
|
||||
$brace = strpos($data, '}');
|
||||
// Either ; or } must exist.
|
||||
if (!$semicolon && !$brace) {
|
||||
if (! $semicolon && ! $brace) {
|
||||
return false;
|
||||
}
|
||||
// But neither must be in the first X characters.
|
||||
@ -127,10 +127,10 @@ if (! function_exists('is_serialized')) {
|
||||
switch ($token) {
|
||||
case 's':
|
||||
if ($strict) {
|
||||
if ('"' !== substr($data, -2, 1)) {
|
||||
if (substr($data, -2, 1) !== '"') {
|
||||
return false;
|
||||
}
|
||||
} elseif (!strpos($data, '"')) {
|
||||
} elseif (! strpos($data, '"')) {
|
||||
return false;
|
||||
}
|
||||
// Or else fall through.
|
||||
@ -162,44 +162,93 @@ if (! function_exists('maybe_unserialize')) {
|
||||
*/
|
||||
function maybe_unserialize($data)
|
||||
{
|
||||
if (is_serialized($data)) { // Don't attempt to unserialize data that wasn't serialized going in.
|
||||
return @unserialize(trim($data));
|
||||
if (! is_string($data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = trim($data);
|
||||
// Don't attempt to unserialize data that wasn't serialized going in.
|
||||
if (is_serialized($data)) {
|
||||
return unserialize(trim($data));
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('cel2Fah')) {
|
||||
/**
|
||||
|--------------------------------------------------------------------------
|
||||
| Metric functions
|
||||
|--------------------------------------------------------------------------
|
||||
| Functions that convert from metric to imperial or from a smaller
|
||||
| metric unit to a larger one.
|
||||
|
|
||||
*/
|
||||
|
||||
if (! function_exists('centimeters2Inches')) {
|
||||
/**
|
||||
* Convert from celsius to fahrenheit.
|
||||
* Convert from centimeters to inches.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $celsius
|
||||
* @param float|int|string $centimeters
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function cel2Fah($celsius, int $preceision = 0): float
|
||||
function centimeters2Inches($centimeters, int $preceision = 1): float
|
||||
{
|
||||
return round((($celsius * (9/5)) + 32), $preceision);
|
||||
return round(($centimeters / 2.54), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('fah2Cel')) {
|
||||
if (! function_exists('centimeters2Feet')) {
|
||||
/**
|
||||
* Convert from fahrenheit to celsius.
|
||||
* Convert from centimeters to inches.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $fahrenheit
|
||||
* @param float|int|string $centimeters
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function fah2Cel($fahrenheit, int $preceision = 1): float
|
||||
function centimeters2Feet($centimeters, int $preceision = 1): float
|
||||
{
|
||||
return round(($fahrenheit - 32 * (5/9)), $preceision);
|
||||
return round((($centimeters / 2.54) * 12), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('centimeters2Meters')) {
|
||||
/**
|
||||
* Convert from centimeters to meters.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $centimeters
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function centimeters2Meters($centimeters, int $preceision = 1): float
|
||||
{
|
||||
return round(($centimeters / 100), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('centimeters2Yards')) {
|
||||
/**
|
||||
* Convert from centimeters to yards.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $centimeters
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function centimeters2Yards($centimeters, int $preceision = 1): float
|
||||
{
|
||||
return round(($centimeters / 91.44), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,7 +286,7 @@ if (! function_exists('kilometers2Miles')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('m2Km')) {
|
||||
if (! function_exists('meters2Kilometers')) {
|
||||
/**
|
||||
* Convert from meters to kilometers.
|
||||
*
|
||||
@ -248,29 +297,148 @@ if (! function_exists('m2Km')) {
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function m2Km($meters, int $preceision = 1): float
|
||||
function meters2Kilometers($meters, int $preceision = 1): float
|
||||
{
|
||||
return round(($meters / 1000), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('mm2Inches')) {
|
||||
if (! function_exists('celsius2Fahrenheit')) {
|
||||
/**
|
||||
* Convert from milimeters to inches.
|
||||
* Convert from celsius to fahrenheit.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $milimeters
|
||||
* @param float|int|string $celsius
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function mm2Inches($milimeters, int $preceision = 1): float
|
||||
function celsius2Fahrenheit($celsius, int $preceision = 0): float
|
||||
{
|
||||
return round(($milimeters / 25.4), $preceision);
|
||||
return round((($celsius * (9/5)) + 32), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('millimeters2Inches')) {
|
||||
/**
|
||||
* Convert from millimeters to inches.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $millimeters
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function millimeters2Inches($millimeters, int $preceision = 1): float
|
||||
{
|
||||
return round(($millimeters / 25.4), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|--------------------------------------------------------------------------
|
||||
| Imperial functions
|
||||
|--------------------------------------------------------------------------
|
||||
| Functions that convert from imperial to metric or from a smaller
|
||||
| imperial unit to a larger one.
|
||||
|
|
||||
*/
|
||||
|
||||
if (! function_exists('inches2Millimeters')) {
|
||||
/**
|
||||
* Convert from inches to millimeters.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $inches
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function inches2Millimeters($inches, int $preceision = 1): float
|
||||
{
|
||||
return round(($inches * 2.54), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('inches2Meters')) {
|
||||
/**
|
||||
* Convert from inches to meters.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $inches
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function inches2Meters($inches, int $preceision = 1): float
|
||||
{
|
||||
return round(($inches / 39.37), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('inches2Yards')) {
|
||||
/**
|
||||
* Convert from inches to yards.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $inches
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function inches2Yards($inches, int $preceision = 1): float
|
||||
{
|
||||
return round(($inches / 36), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('inches2Feet')) {
|
||||
/**
|
||||
* Convert from inches to feet.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $inches
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function inches2Feet($inches, int $preceision = 1): float
|
||||
{
|
||||
return round(($inches * 12), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('fahrenheit2Celsius')) {
|
||||
/**
|
||||
* Convert from fahrenheit to celsius.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $fahrenheit
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function fahrenheit2Celsius($fahrenheit, int $preceision = 1): float
|
||||
{
|
||||
return round(($fahrenheit - 32 * (5/9)), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|--------------------------------------------------------------------------
|
||||
| Miscellaneous functions
|
||||
|--------------------------------------------------------------------------
|
||||
| Functions that don't really belong to the other two categories.
|
||||
|
|
||||
*/
|
||||
|
||||
if (! function_exists('pa2Mbar')) {
|
||||
/**
|
||||
* Convert from pascals to milibars.
|
||||
|
Loading…
x
Reference in New Issue
Block a user