Reference - Parms functions - substr


App: regression/common - Page: misc/eval


App: regression/framework - Page: expressions/a_built_in_written_as_a_call_reads_its_first_argument
PHP
HTML
expressions/a_built_in_written_as_a_call_reads_its_first_argument.pad
Result
{set $s = 'hello'}[{echo trim('  a  ')}][{echo upper($s)}][{echo left($s, 2)}][{if upper($s) eq 'HELLO'}T{else}F{/if}][{echo 'x' . upper($s)}][{echo date('Y', 0)}][{echo $s | replace('l', upper('x'))}][{echo substr($s, 0, 3)}][{echo $s | left(2)}][{$s | left(3)}]


App: regression/framework - Page: expressions/a_sign_before_a_field_a_group_or_a_call_negates_it
PHP
expressions/a_sign_before_a_field_a_group_or_a_call_negates_it.php
HTML
expressions/a_sign_before_a_field_a_group_or_a_call_negates_it.pad
Result
<?php

$a
= 5;
$b = 3;
$n = 2;
$neg = -4;

?>
[{echo 5 * -$b}][{echo $a - -$b}][{echo 5 * -(1 + 2)}][{echo 10 / -$n}][{echo 2 ** -$n}]
[{echo 5 * - 3}][{echo 2 - - 3}][{echo 3 - -$n * 2}][{echo 5 * -php:abs(3)}][{echo 1 + +$b}]
[{echo 10 | * -$n}][{echo 'abcdef' | substr(-$n)}][{echo 'abcdef' | substr(1, -$n)}][{echo php:max(1, -$n)}]
[{if $neg gt -$b}T{else}F{/if}][{echo -$b}][{echo 10 | - 3}]


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

// A text with a byte that is no UTF-8, far before its end: it is cut in code points, as
// the same text is when the byte stands near the end.

$tail = "ab\u{1F1F3}\u{1F1F1}e\u{301}";
$long = "\xFF" . str_repeat ( 'a', 5000 ) . $tail;
$short = "\xFF" . str_repeat ( 'a', 10 ) . $tail;

?>
[{echo $long | right(1) | php:bin2hex(@)}][{echo $long | right(2) | php:bin2hex(@)}][{echo $long | substr(-3, 1) | php:bin2hex(@)}][{echo $short | right(1) | php:bin2hex(@)}]


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/substr_and_max_len_read_an_empty_count_as_a_number
PHP
functions/substr_and_max_len_read_an_empty_count_as_a_number.php
HTML
functions/substr_and_max_len_read_an_empty_count_as_a_number.pad
Result
<?php

$len
= '';

?>
[{echo 'Hello' | substr(1, $len)}][{echo 'Hello' | substr($len)}][{echo 'Hello' | max_len($len)}][{echo 'Hello' | substr(1.5)}]


App: regression/framework - Page: functions/substr_counts_from_zero
PHP
HTML
functions/substr_counts_from_zero.pad
Result
{echo 'Hello World' | substr(6)}


App: regression/framework - Page: functions/substr_from_the_right
PHP
HTML
functions/substr_from_the_right.pad
Result
{echo 'abcdef' | substr(-2)}


App: regression/framework - Page: functions/substr_past_the_end_gives_nothing
PHP
HTML
functions/substr_past_the_end_gives_nothing.pad
Result
{echo 'abc' | substr(20)}


App: regression/framework - Page: functions/substr_with_a_length
PHP
HTML
functions/substr_with_a_length.pad
Result
{echo 'Hello World' | substr(0, 5)}


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: tags/a_pipe_function_used_as_a_tag_wins_over_php
PHP
HTML
tags/a_pipe_function_used_as_a_tag_wins_over_php.pad
Result
[{substr 0, 2}abcdef{/substr}][{trim}  x  {/trim}][{echo php:substr('abc', 1)}]


App: regression/pages - Page: select/support/topic
PHP
HTML
select/support/topic.pad
Result
{content 'who'}
{users}
<p>@content@ by {$username}
{/users}
on {$created_at | substr (0, 16)}</p>
{/content}

{forum_topics $id=1}

{forum_boards}
<h1>Board: {$name}</h1>
{/forum_boards}

<h2>Topic: {$title}</h2>

{who}Started{/who}

{forum_posts}

<hr>

{who}Posted{/who}

<p>{$content}</p>

@else@

<p>No posts yet</p>

{/forum_posts}

{/forum_topics}