fork download
  1. <?php
  2.  
  3. $code = "function lol()
  4. {
  5. echo('omg');
  6. num=0;
  7. while(num<100)
  8. {
  9. echo('ok');
  10. }
  11. }
  12.  
  13. function teste()
  14. {
  15. echo('ola');
  16. while(num<100){
  17. echo('ok');
  18. }
  19. }
  20. function test()
  21. {
  22. echo('oi');
  23. while(num<100)
  24. {
  25. echo('ok');
  26. }
  27. }";
  28.  
  29. $result = preg_replace_callback('#(.*?)\{((?:[^{}]|(?R))*)\}|.*#si', function($m){
  30. if(isset($m[1], $m[2]) && preg_match('#function\s+teste\b#i', $m[1])){
  31. return $m[2];
  32. }
  33. }, $code);
  34.  
  35. echo $result;
  36. ?>
Success #stdin #stdout 0.01s 20616KB
stdin
Standard input is empty
stdout
    echo('ola');
    while(num<100){
    echo('ok');
    }