note 119959 added to function.vsprintf
| From: | spectrumcat | Date: | Wed, 28 Sep 2016 10:51:43 +0000 |
| Subject: | note 119959 added to function.vsprintf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206694@lists.php.net to get a copy of this message | ||
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);
----
Server IP: 72.52.91.14
Probable Submitter: 83.219.72.162
----
Manual Page -- http://php.net/manual/en/function.vsprintf.php
Edit -- https://master.php.net/note/edit/119959
Del: integrated -- https://master.php.net/note/delete/119959/integrated
Del: useless -- https://master.php.net/note/delete/119959/useless
Del: bad code -- https://master.php.net/note/delete/119959/bad+code
Del: spam -- https://master.php.net/note/delete/119959/spam
Del: non-english -- https://master.php.net/note/delete/119959/non-english
Del: in docs -- https://master.php.net/note/delete/119959/in+docs
Del: other reasons-- https://master.php.net/note/delete/119959
Reject -- https://master.php.net/note/reject/119959
Search -- https://master.php.net/manage/user-notes.php