16.4. Outputting measurements

Measurements can be output in a number of different ways.

Automatic output

Outputting values

Output with unit of measurement

Output as localized string

16.4.1. Automatic output

Zend_Measure supports outputting of strings automatically.

Przykład 16.8. Automatic output

<?php
require_once 'Zend.php';
Zend::loadClass('Zend_Measure');

$locale = new Zend_Locale('de');
$mystring = "1.234.567,89 Meter";
$unit = new Zend_Measure($mystring,Zend_Measure::LENGTH, $locale);

echo $unit;
?>

[Notatka] Measurement output

Output can be achieved simply by using echo or print .

16.4.2. Outputting values

The value of a measurement can be output using getValue().

Przykład 16.9. Output a value

<?php
require_once 'Zend.php';
Zend::loadClass('Zend_Measure');

$locale = new Zend_Locale('de');
$mystring = "1.234.567,89 Meter";
$unit = new Zend_Measure($mystring,Zend_Measure::LENGTH, $locale);

echo $unit->getValue();
?>

16.4.3. Output with unit of measurement

The function getType() returns the current unit of measurement.

Przykład 16.10. Outputting units

<?php
require_once 'Zend.php';
Zend::loadClass('Zend_Measure');
Zend::loadClass('Zend_Measure_Weight');

$locale = new Zend_Locale('de');
$mystring = "1.234.567,89";
$unit = new Zend_Measure($mystring,Zend_Measure_Weight::POUND, $locale);

echo $unit->getType();
?>

16.4.4. Output as localized string

Outputtig a string in a format common in the users' country is usually desirable.

For example, the measurement "1234567.8" would become "1.234.567,8" for Germany.

[Notatka] Notatka

This functionality will be supported in a future release.