Programmer's Reference Guide
| Creation of Measurements |
Outputting measurements
Measurements can be output in a number of different ways.
Output with unit of measurement
Automatic output
Zend_Measure supports outputting of strings automatically.
Пример #1 Automatic output
<?php
require_once 'Zend/Measure/Length.php';
$locale = new Zend_Locale('de');
$mystring = "1.234.567,89 Meter";
$unit = new Zend_Measure_Length($mystring,Zend_Measure_Length::STANDARD, $locale);
echo $unit;
Замечание: Measurement output
Output can be achieved simply by using »echoor »
Outputting values
The value of a measurement can be output using getValue().
Пример #2 Output a value
<?php
require_once 'Zend/Measure/Length.php';
$locale = new Zend_Locale('de');
$mystring = "1.234.567,89 Meter";
$unit = new Zend_Measure_Length($mystring,Zend_Measure_Length::STANDARD, $locale);
echo $unit->getValue();
The getValue() method accepts an optional parameter 'round' which allows to
define a precision for the generated output. The standard precision is '2'.
Output with unit of measurement
The function getType() returns the current unit of measurement.
Пример #3 Outputting units
<?php
require_once 'Zend/Measure/Weight.php';
$locale = new Zend_Locale('de');
$mystring = "1.234.567,89";
$unit = new Zend_Measure_Weight($mystring,Zend_Measure_Weight::POUND, $locale);
echo $unit->getType();
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. This functionality will be supported in a future release.
| Creation of Measurements |
