[ create a new paste ] login | about

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

PHP, pasted on Sep 29:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php

$song = "arctic Monkeys- a fake tales of a san francisco";

$words = preg_split("/([\s]+|(?=-))/", $song);

print_r($words);

$new_words = array();
foreach ($words as $k => $word) {
    $new_words[] = processWord($word, $k, $words);
}

echo implode(' ', $new_words);

function processWord($word, $idx, $words) {
    if ($words[$idx - 1] == '-') return ucfirst($word);
    return strlen($word) > 2 ? ucfirst($word) : $word;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Array
(
    [0] => arctic
    [1] => Monkeys
    [2] => -
    [3] => a
    [4] => fake
    [5] => tales
    [6] => of
    [7] => a
    [8] => san
    [9] => francisco
)
Arctic Monkeys - A Fake Tales of a San Francisco


Create a new paste based on this one


Comments: