[ create a new paste ] login | about

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

PHP, pasted on Apr 10:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
$bands = array(
    1 => 'Metallica',
    2 => 'Megadeth',
    3 => 'Anthrax',
    4 => 'Slayer',
    5 => 'Black Sabbath',
);

$text = "My first favorite band is: #band{2}, and after that it's: #band1. My over-all first metal band was: #band{5}, and I sometimes enjoy headbaning while listening to: #band3 or #band{4}.";

$out = preg_replace_callback('!\#band\{(\d+)\}!', 'replace_band', $text);

function replace_band($m){
    return $GLOBALS['bands'][$m[1]];
}

print_r($out);


Output:
1
My first favorite band is: Megadeth, and after that it's: #band1. My over-all first metal band was: Black Sabbath, and I sometimes enjoy headbaning while listening to: #band3 or Slayer.


Create a new paste based on this one


Comments: