Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/styllloz/public_html/qa-include/qa-base.php on line 1175

Warning: session_start(): Cannot start session when headers already sent in /home/styllloz/public_html/qa-include/app/users.php on line 162

Warning: Cannot modify header information - headers already sent by (output started at /home/styllloz/public_html/qa-include/qa-base.php:1175) in /home/styllloz/public_html/qa-include/app/users.php on line 1267

Warning: Cannot modify header information - headers already sent by (output started at /home/styllloz/public_html/qa-include/qa-base.php:1175) in /home/styllloz/public_html/qa-include/app/page.php on line 356
Looking for a class function to iterate through all possible variants of a line - code-flow.club | Q&A

Looking for a class function to iterate through all possible variants of a line


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
8 views
Good afternoon everyone.

Looking for a class (function) in PHP to iterate through all possible variants of a line formed from such structures {||}.

Absolutely great would be if Robin will go from the most unique line to the most unique.
by | 8 views

2 Answers

0 like 0 dislike
Recently on Habre slipped a crop top. The link is not kept, only the code:
\r
<?\r\r$str = "{Пожалуйста|Просто} сделайте так, чтобы это {удивительное|крутое|простое} тестовое предложение {изменялось {быстро|мгновенно} случайным образом|менялось каждый раз}";\r$finishStrs = array();\r\rgetVariants($str);\r\rfunction getVariants($str) {\rglobal $finishStrs;\r$strs = array();\r\r\rif(preg_match("~\\{([^{}]+)\\}~siU", $str, $m)) {\r\r$foundExpression = $m[1];\r\r$currentVariants = explode("|", $foundExpression);\r\rforeach($currentVariants as $var) {\r$strs[] = str_replace('{'.$foundExpression.'}', $var, $str);\r}\r\rforeach($strs as $currentStr) {\rif(preg_match("~\\{([^{}]+)\\}~siU", $currentStr, $m)) {\rgetVariants($currentStr);\r} else {\r$finishStrs[] = $currentStr;\r}\r}\r\r} else {\r$finishStrs = $str;\r}\r\r\r}\r\rprint_r($finishStrs);\r</code>
by
0 like 0 dislike
those who suddenly came here by googling my problem in the job — this algorithm does not take into account the positional feature of entry and is not valid in the General case (not for this specific line).
by

Related questions

0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
3 answers
110,608 questions
257,186 answers
0 comments
35,189 users