Source for file Length.php
Documentation is available at Length.php
* Represents a measurable length, with a string numeric magnitude
* and a unit. This object is immutable.
* String numeric magnitude.
* String unit. False is permitted if $n = 0.
* Whether or not this length is valid. Null if not calculated yet.
* Lookup array of units recognized by CSS 2.1
protected static $allowedUnits =
array(
'em' =>
true, 'ex' =>
true, 'px' =>
true, 'in' =>
true,
'cm' =>
true, 'mm' =>
true, 'pt' =>
true, 'pc' =>
true
* @param number $n Magnitude
$this->unit =
$u !==
false ? (string)
$u :
false;
* @param string $s Unit string, like '2em' or '3.4in'
* @warning Does not perform validation.
static public function make($s) {
$n_length =
strspn($s, '1234567890.+-');
$n =
substr($s, 0, $n_length);
$unit =
substr($s, $n_length);
if ($unit ===
'') $unit =
false;
* Validates the number and unit.
if ($this->n ===
'+0' ||
$this->n ===
'-0') $this->n =
'0';
if ($this->n ===
'0' &&
$this->unit ===
false) return true;
$result =
$def->validate($this->n, false, false);
if ($result ===
false) return false;
* Returns string representation of number.
if (!$this->isValid()) return false;
return $this->n .
$this->unit;
* Retrieves string numeric magnitude.
public function getN() {return $this->n;}
* Returns true if this length unit is valid.
* Compares two lengths, and returns 1 if greater, -1 if less and 0 if equal.
* @warning If both values are too large or small, this calculation will
if ($l ===
false) return false;
if ($l->unit !==
$this->unit) {
$l =
$converter->convert($l, $this->unit);
if ($l ===
false) return false;
Documentation generated on Thu, 19 Jun 2008 18:49:42 -0400 by phpDocumentor 1.4.2