Reference - PAD functions - replace


App: manual - Page: fragments/expressions_30


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

$rawText
= ' hello world ';
$message = 'the quick brown fox';

?>
<p>Chain multiple pipes together:</p>

<p>Original: [{$rawText}]</p>
<p>Trimmed and uppercase: [{echo $rawText | trim | upper}]</p>

<p>Original: {$message}</p>
<p>Uppercase first letter of each word: {echo $message | ucwords}</p>
<p>Replace and capitalize each word: {echo $message | replace('fox', 'dog') | ucwords}</p>


App: regression/errors - Page: eval/a_built_in_call_short_of_parameters_says_its_value_comes_first
PHP
HTML
eval/a_built_in_call_short_of_parameters_says_its_value_comes_first.pad
Result
{echo replace('a', 'b')}


App: regression/errors - Page: syntax/a_function_wants_its_parameters
PHP
HTML
syntax/a_function_wants_its_parameters.pad
Result
{set $x = 'abc'/}[{$x | replace('b')}]


App: regression/framework - Page: check/fragments_pipes_3
PHP
check/fragments_pipes_3.php
HTML
check/fragments_pipes_3.pad
Result
<?php

$rawText
= ' hello world ';
$message = 'the quick brown fox';

?>
<p>Chain multiple pipes together:</p>

<p>Original: [{$rawText}]</p>
<p>Trimmed and uppercase: [{echo $rawText | trim | upper}]</p>

<p>Original: {$message}</p>
<p>Uppercase first letter of each word: {echo $message | ucwords}</p>
<p>Replace and uppercase: {echo $message | replace('fox', 'dog') | ucwords}</p>


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_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: expressions/an_infix_test_as_an_argument_of_a_call_is_that_argument
PHP
HTML
expressions/an_infix_test_as_an_argument_of_a_call_is_that_argument.pad
Result
{set $n = 3}{set $s = 'ab'}[{echo php:var_export($n in (5), 1)}][{echo php:strval($n in (3))}][{echo php:max(1, $n + 1 in (4))}][{echo php:var_export($n not in (5), 1)}][{echo php:var_export(php:substr($s, 0, 1) like 'a%', 1)}][{echo php:str_repeat('x', $n in (3) ? 2 : 1)}][{echo $s | replace('a', $n in (3))}][{echo php:max(php:min(4, 9), $n range (1, 5))}][{echo php:max(1, in (3))}]


App: regression/framework - Page: expressions/an_inline_ternary_as_an_argument_is_that_argument_only
PHP
HTML
expressions/an_inline_ternary_as_an_argument_is_that_argument_only.pad
Result
{set $n = 5}{set $s = 'banana'}{set $z = 0}[{echo $s | replace('a', $n gt 1 ? 'x' : 'y')}][{echo php:str_repeat('-', $n gt 0 ? $n : 1)}][{echo php:str_repeat($n gt 0 ? '+' : '-', 3)}][{echo php:max($n gt 3 ? 1 : 9, $z ? 4 : 2)}][{echo php:max($z ? 1 : php:min(8, 7), 3)}][{echo php:implode('-', [1, $n gt 3 ? 2 : 0, 3])}][{echo $s | replace('a', $n gt 9 ? 'x' : $n gt 4 ? 'm' : 's')}]


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

$subject
= 'Order 12, shipped';

?>
1[{echo 'Re: {$subject}' | url}] 2[{echo 'Re: {$subject}' | contains(',')}] 3[{echo 'Re: {$subject}' | replace(', ', ' - ')}] 4[{echo 'Re: {$subject}' | after(',')}] 5[{echo 'Re: {$subject}' | escape('js')}]


App: regression/framework - Page: functions/a_list_parameter_is_taken_where_the_function_takes_one
PHP
HTML
functions/a_list_parameter_is_taken_where_the_function_takes_one.pad
Result
1[{echo 'abc' | replace(['a', 'b'], ['x', 'y'])}] 2[{echo 'abc' | cut(['a', 'c'])}] 3[{echo 'b' | in(['a', 'b'])}] 4[{echo [1, 2] | contains(2)}] 5[{echo '' | default(['x', 'y']) | php:count}] 6[{echo 'b' in ('a', 'b')}]


App: regression/framework - Page: functions/a_null_handed_along_a_pipe_chain_is_empty_to_the_next_function
PHP
HTML
functions/a_null_handed_along_a_pipe_chain_is_empty_to_the_next_function.pad
Result
[{echo 'https://example.com/page' | php:parse_url(@, PHP_URL_QUERY) | trim}][{echo 'https://example.com/page' | php:parse_url(@, PHP_URL_QUERY) | html}][{echo 'https://example.com/page' | php:parse_url(@, PHP_URL_QUERY) | left(3)}][{echo 'https://example.com/page' | php:parse_url(@, PHP_URL_QUERY) | replace('a', 'b')}][{echo 'https://example.com/page' | php:parse_url(@, PHP_URL_QUERY) | url}][{echo 'https://example.com/page' | php:parse_url(@, PHP_URL_QUERY) | default('none')}]


App: regression/framework - Page: functions/replace
PHP
HTML
functions/replace.pad
Result
{echo 'hello world' | replace('world', 'there')}


App: regression/framework - Page: functions/replace_with_no_match_leaves_it_alone
PHP
HTML
functions/replace_with_no_match_leaves_it_alone.pad
Result
{echo 'abc' | replace('z', 'y')}


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

// The lenient walk under test: with the syntax check off, what cannot run passes the
// value through or yields empty, and the walk carries on.

$padCheckSyntax = FALSE;

?>
{set $x = 'abc'/}[{$x | replace('b')}]