Created
September 4, 2011 16:14
-
-
Save varnie/1193086 to your computer and use it in GitHub Desktop.
Yet another programming challenge to blow up your mind (PHP version).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$src = '{Пожалуйста|Просто} сделайте так, чтобы это {удивительное|крутое|простое} тестовое предложение {изменялось {быстро|мгновенно} случайным образом|менялось каждый раз}'; | |
while (preg_match("/\{([^\{\}]*)\}/", $src, $matches)){ | |
$alt_items = explode("|", $matches[1]); | |
$item = $alt_items[array_rand($alt_items)]; | |
$src = str_replace($matches[0], $item, $src); | |
} | |
print $src; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment