Skip to content

Instantly share code, notes, and snippets.

@varnie
Created September 4, 2011 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varnie/1193086 to your computer and use it in GitHub Desktop.
Save varnie/1193086 to your computer and use it in GitHub Desktop.
Yet another programming challenge to blow up your mind (PHP version).
<?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