Reference - Parms functions - mid


App: manual - Page: fragments/expressions_31


App: regression/framework - Page: check/miscellaneous_other
PHP
HTML
check/miscellaneous_other.pad
Result
<h3>part 1</h3>  
{set $abc = (15 gt 33) } eq {$abc}


<h3>part 3</h3>

{if ( PHP_EOL EQ "\n" ) and ( PHP_EOL EQ 0x0a) }
ok
@else@
NOK
{/if}

<h3>part 4</h3>

{set $abc = ''}
{set $klm = 0}
{set $xyz = 'ok'}

<h3>part 6</h3>

{set $abc = 'abc'}
{set $xyz = 'xyz'}

{$abc | mid (2,1)}
{$abc | mid ( 2 , 1 )}

<h3>part 10</h3>

{if 5 gt 3}
ok
@else@
NOK
{/if}

{if 3 gt 5}
NOK
@else@
ok
{/if}

{if 5 gt 3 and 7 gt 6}
ok
@else@
NOK
{/if}


{if 3 gt 5 or 6 gt 7}
NOK
@else@
ok
{/if}


{if 1 gt 1 and 1 gt 1 and 1 gt 1 and 1 gt 1 and 1 gt 1 }
NOK
@else@
ok
{/if}

{if 1 gt 1 and 1 gt 1 and 1 gt 1 and 1 gt 1 or 5 gt 4 }
ok
@else@
NOK
{/if}


{if (1 gt 1) or ( 1 gt 1 or ( 1 gt 1 or (1 gt 1 or (5 gt 4) ) ) ) }
ok
@else@
NOK
{/if}

{if (1 gt 1) or ( 1 gt 1 or ( 1 gt 1 or (1 gt 1 or (5 gt 6) ) ) ) }
NOK
@else@
ok
{/if}

<h3>part 11c</h3>

{if 3 gt 5 or 6 gt 7}
NOK
@else@
ok
{/if}
{if 3 gt 5 or 6 gt 7}
NOK
@else@
ok
{/if}
{if 3 gt 5 or 6 gt 7}
NOK
@else@
ok
{/if}


App: regression/framework - Page: expressions/a_pipe_in_brackets_after_a_call_with_arguments_runs_every_part
PHP
HTML
expressions/a_pipe_in_brackets_after_a_call_with_arguments_runs_every_part.pad
Result
{echo (mid('hello', 1, 2) | ucfirst)} {echo (php:max(1, 2, 3) | + 1)} {echo upper(('ab' | replace('a', 'x')))} {echo ('x' | left(2) | . '!')}


App: regression/framework - Page: functions/a_mid_start_below_one_is_read_as_one
PHP
HTML
functions/a_mid_start_below_one_is_read_as_one.pad
Result
{echo 'abc' | mid(0, 1)}


App: regression/framework - Page: functions/a_negative_mid_length_is_nothing
PHP
HTML
functions/a_negative_mid_length_is_nothing.pad
Result
{echo 'abc' | mid(2, -1)}


App: regression/framework - Page: functions/cuts_count_characters_not_bytes
PHP
HTML
functions/cuts_count_characters_not_bytes.pad
Result
{echo 'Zoë Müller' | left(3)}|{echo 'Zoë Müller' | right(6)}|{echo 'Zoë Müller' | mid(3, 3)}|{echo 'Zoë Müller' | substr(2, 3)}|{echo 'Zoë Müller' | max_len(3)}


App: regression/framework - Page: functions/mid_counts_from_one
PHP
HTML
functions/mid_counts_from_one.pad
Result
{echo 'abcdef' | mid(2, 3)}


App: regression/framework - Page: functions/mid_past_the_end_gives_what_is_there
PHP
HTML
functions/mid_past_the_end_gives_what_is_there.pad
Result
{echo 'abc' | mid(2, 10)}


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/pages - Page: catalog/functions
PHP
catalog/functions.php
HTML
catalog/functions.pad
Result
<?php

// The value the stripLow line cleans: printable letters around two control characters.

$catLow = "a\x01b\x02c";

?>
after:      {echo 'a/b' | after('/')}
afterLast: {echo 'a/b/c' | afterLast('/')}
before: {echo 'a/b' | before('/')}
beforeLast: {echo 'a.b.c' | beforeLast('.')}
between: {echo 17 | between(10, 66)}.
bold: {echo 'important' | bold}
close: {echo 'items' | close | ignore}
contains: {echo 12345 | contains('34')}.
cut: {echo 'banana' | cut('an')}
encodeHigh: {echo 'café' | encodeHigh}
exists: {echo 'hello/index.pad' | exists}.
html: {echo '<b>' | html}
in: {echo 'a' | in('a')}.
left: {echo 'abcdef' | left(2)}
like: {echo 'abc' | like('a%')}.
max_len: {echo 'abcdef' | max_len(4)}
mid: {echo 'abcdef' | mid(2, 3)}
nbsp: {echo 'hello world' | nbsp}
open: {echo 'items' | open | ignore}
optional: {$catNoSuch | optional}ok
range: {echo 50 | range(0, 100)}.
replace: {echo 'abc' | replace('b', 'x')}
right: {echo 'abcdef' | right(2)}
sanitize: {echo '<b>x</b>' | sanitize}
slashes: {echo "it's" | slashes}
stripLow: {echo $catLow | stripLow}
stripslashes: {echo "it's" | slashes | stripslashes}
tag: {echo 'items' | tag | ignore}
time: {echo 1702483200 | time('Y')}
timestamp: {echo 1702483200 | timestamp('Y')}
trim: {echo ' a b ' | trim}
ucwords: {echo 'hello world' | ucwords}
white: {echo 'a b' | white}