/hphp/test/zend/good/ext/pcre/tests/preg_replace_callback.php
PHP | 22 lines | 16 code | 6 blank | 0 comment | 1 complexity | 41746d4a3140b716106c70b163add8ec MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
- <?hh
- function parseTagsRecursive($input)
- {
- $regex = '#\[indent]((?:[^[]|\[(?!/?indent])|(?R))+)\[/indent]#';
- if (is_array($input)) {
- $input = '<div style="margin-left: 10px">'.$input[1].'</div>';
- }
- $count = -1;
- return preg_replace_callback($regex, fun('parseTagsRecursive'), $input, -1, inout $count);
- }
- <<__EntryPoint>>
- function main_entry(): void {
- $input = "plain [indent] deep [indent] [abcd]deeper[/abcd] [/indent] deep [/indent] plain";
- $output = parseTagsRecursive($input);
- echo $output, "\n";
- }