Reference - PAD functions - truncate


App: manual - Page: fragments/expressions_31


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

$intro
= 'The quick brown fox jumps over the lazy dog, twice before breakfast';
$title = 'Crème Brûlée & Co.';
$size = 3221225472;
$quote = 'it\'s </script>';

?>
<p>{$intro | truncate(30)}</p>
<p>?page={$title | slug}</p>
<p>{$size | bytes}</p>
<p>{$quote | escape('js')}</p>


App: regression/framework - Page: functions/a_closing_pipe_sees_the_letters_of_its_fields
PHP
functions/a_closing_pipe_sees_the_letters_of_its_fields.php
HTML
functions/a_closing_pipe_sees_the_letters_of_its_fields.pad
Result
<?php

$items
= [ [ 'name' => 'Zoë' ], [ 'name' => 'Tom & Jerry' ], [ 'name' => "O'Neil" ] ];

?>
1[{items}{$name} {/items | upper}] 2[{items}{$name} {/items | truncate(8)}] 3[{items}{$name} {/items | left(4)}]


App: regression/framework - Page: functions/the_cutting_functions_count_the_characters_a_reader_sees
PHP
functions/the_cutting_functions_count_the_characters_a_reader_sees.php
HTML
functions/the_cutting_functions_count_the_characters_a_reader_sees.pad
Result
<?php

$flag
= "\u{1F1F3}\u{1F1F1} NL";
$nfd = "e\u{0301}cole";
$fam = "a\u{1F468}\u{200D}\u{1F469}\u{200D}\u{1F467}";

?>
[{echo $flag | left(1) | php:bin2hex(@)}][{echo $nfd | left(1) | php:bin2hex(@)}][{echo $fam | right(1) | php:bin2hex(@)}][{echo $nfd | mid(2, 2)}][{echo $flag | max_len(1) | php:bin2hex(@)}][{echo $nfd | substr(1)}][{echo $nfd | truncate(3, '.') | php:bin2hex(@)}]


App: regression/framework - Page: functions/the_cutting_functions_keep_a_character_whole_at_the_end_of_a_long_text
PHP
functions/the_cutting_functions_keep_a_character_whole_at_the_end_of_a_long_text.php
HTML
functions/the_cutting_functions_keep_a_character_whole_at_the_end_of_a_long_text.pad
Result
<?php

// Past 4096 bytes right() and substr() from the end read a window at the end of the text,
// not the whole of it: a run of flags, whose pairs count from the run's start, and an
// accent written apart must come out whole there too.

$flags = str_repeat ( "\u{1F1F3}\u{1F1F1}", 3001 );
$accent = str_repeat ( "e\u{0301}", 3000 ) . "ab";

?>
[{echo $flags | right(1) | php:bin2hex(@)}][{echo $flags | substr(-2, 1) | php:bin2hex(@)}][{echo $accent | right(3) | php:bin2hex(@)}][{echo $accent | mid(3000, 1) | php:bin2hex(@)}][{echo $accent | truncate(3, '') | php:bin2hex(@)}]


App: regression/framework - Page: functions/truncate_ends_on_a_whole_word_with_an_ellipsis
PHP
HTML
functions/truncate_ends_on_a_whole_word_with_an_ellipsis.pad
Result
[{echo 'The quick brown fox jumps over the lazy dog' | truncate(20)}][{echo 'Short' | truncate(20)}][{echo 'Supercalifragilistic' | truncate(10)}][{echo 'one two three' | truncate(9, '...')}]


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

// The secret of maintenance mode is asked as ?<secret>: the name of a page every visitor
// asks gave all of them the cookie, and one no address can ask locked its developer out.

$secrets = [];

foreach ( [
'letmein', 'guestbook', 'todo', 'index', 'a', 'a b c d e', 'x&y12345', str_repeat ( 'k', 65 ) ] as $one )
$secrets [] = [ 'secret' => $one, 'valid' => padMaintenanceSecretValid ( 'demo', $one ) ? 'yes' : 'no' ];

?>
{secrets}{$secret | truncate(9)}: {$valid}; {/secrets}


App: regression/framework - Page: lenient/a_list_handed_to_a_pipe_function_as_its_parameter_is_empty
PHP
lenient/a_list_handed_to_a_pipe_function_as_its_parameter_is_empty.php
HTML
lenient/a_list_handed_to_a_pipe_function_as_its_parameter_is_empty.pad
Result
<?php

// The lenient walk: a list where a pipe function wants a value as its parameter is empty.

$padCheckSyntax = FALSE;

?>
1[{echo 'abc' | contains(['a'])}] 2[{echo 'abc' like ['a']}] 3[{echo 'abc' | matches(['a'])}] 4[{echo 'abc' | after(['a'])}] 5[{echo 'abc' | left([1])}] 6[{echo 'abc' | truncate([2])}] 7[{echo 'abc' | escape(['js'])}] 8[{echo 'b' | between(['a'], 'z')}]