PageRenderTime 56ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/good/ext/pcre/tests/preg_replace_callback.php

http://github.com/facebook/hiphop-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
  1. <?hh
  2. function parseTagsRecursive($input)
  3. {
  4. $regex = '#\[indent]((?:[^[]|\[(?!/?indent])|(?R))+)\[/indent]#';
  5. if (is_array($input)) {
  6. $input = '<div style="margin-left: 10px">'.$input[1].'</div>';
  7. }
  8. $count = -1;
  9. return preg_replace_callback($regex, fun('parseTagsRecursive'), $input, -1, inout $count);
  10. }
  11. <<__EntryPoint>>
  12. function main_entry(): void {
  13. $input = "plain [indent] deep [indent] [abcd]deeper[/abcd] [/indent] deep [/indent] plain";
  14. $output = parseTagsRecursive($input);
  15. echo $output, "\n";
  16. }