Reference - Parms functions - abbreviate


App: manual - Page: fragments/expressions_31


App: manual - Page: fragments/numbers_4
PHP
fragments/numbers_4.php
HTML
fragments/numbers_4.pad
Result
<?php

// The PHP hands over plain numbers; the template writes them
// for people.

$runners = [
[
'name' => 'Ann', 'place' => 1, 'views' => 1534200 ],
[
'name' => 'Bob', 'place' => 2, 'views' => 48210 ],
[
'name' => 'Cee', 'place' => 3, 'views' => 950 ]
];

?>
{runners}
<p>{$place | ordinal}: {$name},
{$views | abbreviate(1)} views</p>
{/runners}


App: regression/errors - Page: syntax/numbers_a_precision_above_a_hundred_is_reported
PHP
syntax/numbers_a_precision_above_a_hundred_is_reported.php
HTML
syntax/numbers_a_precision_above_a_hundred_is_reported.pad
Result
<?php

// A precision below PHP_INT_MAX but far past what a number holds made number_format
// allocate that many bytes: 1e18 decimals ended the request out of memory.

$p = 1e18;

?>
{echo 1500 | abbreviate($p)}


App: regression/errors - Page: syntax/numbers_a_precision_cannot_be_negative
PHP
HTML
syntax/numbers_a_precision_cannot_be_negative.pad
Result
{echo 1500 | abbreviate(-1)}


App: regression/errors - Page: syntax/numbers_a_precision_past_any_whole_number_is_reported
PHP
HTML
syntax/numbers_a_precision_past_any_whole_number_is_reported.pad
Result
{echo 1500 | abbreviate('1e20')}


App: regression/framework - Page: helpers/numbers_abbreviate_pipe_shortens_a_number_in_a_template
PHP
helpers/numbers_abbreviate_pipe_shortens_a_number_in_a_template.php
HTML
helpers/numbers_abbreviate_pipe_shortens_a_number_in_a_template.pad
Result
<?php

$visits
= 1534200;
$likes = 950;

?>
{$visits | abbreviate} {$visits | abbreviate(1)} {$visits | abbreviate(2)} {$likes | abbreviate} {echo 1500 | abbreviate} {echo 999999 | abbreviate} {echo -2500 | abbreviate(1)} [{echo 'many' | abbreviate}] [{echo '' | abbreviate}]