[ create a new paste ] login | about

Link: http://codepad.org/KfP3g02m    [ raw code | output | fork ]

PHP, pasted on Feb 23:
1
2
3
4
5
6
<?
$string = ":abc and :def have apples.";
$replacements = array('abc' => 'Mary', 'def' => 'Jane');

echo preg_replace("/:(\w+)/e", '$replacements[$1]', $string);
?>


Output:
1
Mary and Jane have apples.


Create a new paste based on this one


Comments: