HTMLPurifier_Length::make PHP Method

make() public static method

public static make ( string $s ) : HTMLPurifier_Length
$s string Unit string, like '2em' or '3.4in'
return HTMLPurifier_Length
    public static function make($s)
    {
        if ($s instanceof HTMLPurifier_Length) {
            return $s;
        }
        $n_length = strspn($s, '1234567890.+-');
        $n = substr($s, 0, $n_length);
        $unit = substr($s, $n_length);
        if ($unit === '') {
            $unit = false;
        }
        return new HTMLPurifier_Length($n, $unit);
    }

Usage Example

Ejemplo n.º 1
0
 protected function assertConversion($input, $expect, $unit = null, $test_negative = true)
 {
     $length = HTMLPurifier_Length::make($input);
     if ($expect !== false) {
         $expectl = HTMLPurifier_Length::make($expect);
     } else {
         $expectl = false;
     }
     $to_unit = $unit !== null ? $unit : $expectl->getUnit();
     $converter = new HTMLPurifier_UnitConverter(4, 10);
     $result = $converter->convert($length, $to_unit);
     if (!$result || !$expectl) {
         $this->assertIdentical($result, $expectl);
     } else {
         $this->assertIdentical($result->toString(), $expectl->toString());
     }
     $converter = new HTMLPurifier_UnitConverter(4, 10, true);
     $result = $converter->convert($length, $to_unit);
     if (!$result || !$expectl) {
         $this->assertIdentical($result, $expectl);
     } else {
         $this->assertIdentical($result->toString(), $expectl->toString(), 'BCMath substitute: %s');
     }
     if ($test_negative) {
         $this->assertConversion("-{$input}", $expect === false ? false : "-{$expect}", $unit, false);
     }
 }
All Usage Examples Of HTMLPurifier_Length::make