MEASURE UNITS PX, CM, IN, MM CONVERSION IN PHP FUNCTION

0.53K views
2 Comments
7 Oct 2017 3:11 pm
function measure_conversation($value = null, $measurein = null, $returnin = 'px', $return_value = true){
    $measurein = preg_replace('/[^a-zA-Z0-9]/','',$measurein);
    $value = preg_replace('/[^\d]/','', $value);
    if (!is_numeric($value) && $measurein === null) {
        return false;
    }
    switch (strtolower($measurein)) {
        case "pt":
            $px = $value * (1.333333333333);
            $pt = $value;
            $mm = $value * (0.3527777777778);
            $cm = $value * (0.03527777777778);
            $in = $value * (0.01388888888889);
            break;</pre>
<pre>        case "px":
            $px = $value;
            $pt = 3 / 4 * $value;
            $mm = $value * (0.2645833333333);
            $cm = $value * (0.02645833333333);
            $in = $value / 96;
            break;
        case "mm":
            $px = $value * (3.779528);
            $pt = $value * (2.83465);
            $mm = $value;
            $cm = $value * (0.1);
            $in = $value * (0.0393701);
            break;
        case "in":
            $px = $value * (96);
            $pt = $value * (72);
            $mm = $value * (25.4);
            $cm = $value * (2.54);
            $in = $value;
            break;
        case "cm":
            $px = $value * (37.795275590551);
            $pt = $value * (28.34645669291);
            $mm = $value * (10);
            $cm = $value;
            $in = $value * (0.3937007874015);
            break;
    }
    $return_array = array(
        'px' => $px
        , 'pt' => $pt
        , 'mm' => $mm
        , 'cm' => $cm
        , 'in' => $in
    );
    $return_val = $return_array[$returnin];
    if ($measurein == $returnin) {
        return $value . $returnin;
    }
    if ($return_value === false) {
        return $return_array;
    } else {
        return $return_val . $returnin;
    }
}

NOTE:Your Email Address will be not shown and please do not add spamming comments because here is REL="NOFOLLOW" on your links and comments also moderated shown.
<code>Put html css or any language code under this tag</code>

2 Comments on MEASURE UNITS PX, CM, IN, MM CONVERSION IN PHP FUNCTION
  • I see 2 different errors.
    1) $value = preg_replace(‘/[^\d]/’,”, $value); // quotation error
    2) millimeter values are incorrect