codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
<?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; }
Private
[
?
]
Run code
Submit