CakeFest 2025 Madrid: The Official CakePHP Conference

Voting

: nine plus zero?
(Example: nine)

The Note You're Voting On

spectrumcat
8 years ago
Instead of inventing own functions in case you'd like to use array keys as placeholder names and replace corresponding array values in a string, just use the str_replace:

$string = 'Hello %name!';
$data = array(
'%name' => 'John'
);

$greeting = str_replace(array_keys($data), array_values($data), $string);

<< Back to user notes page

To Top