2014-12-15 6 views
0

저는 ob_start를 처음 사용하고 있습니다.이 함수가 붙어 있습니다!ob_start "함수 동결"매개 변수

텍스트에서 일부 태그를 구문 분석하고 함수에서 다른 텍스트 리턴 세트로 바꿔야했습니다.

http://codepad.viper-7.com/SjKqS1

<html> 
<body> 
    <?php 

    $data = <<<EOF 

LAST_NAME : 문제는, 내가 쉘의 코드를 게시 ... 내가위한 ob_start 호출 할 때, 수행 기능을 모든 sequentials에 대한 첫 번째 매개 변수가 전화를 유지 나의 설명에 대한 유감입니다 , FIRST_NAME [시험 명 = 12] 칼 다시 김 수은 [시험 명 = 3] dsdss dsddsdsds sabanana dsdsdsds [시험 명 = "ABCDEFG"] frickenoich EOF;

$tag = 'test'; 

    $re = "/\\[". $tag ."[\\]| ]/m"; 

    preg_match_all($re, $data, $match); 

    $re = "/\[" . $tag . " (.*)\=([\"|\'|[:alnum:]]*)]/m"; 

    $count = preg_match_all($re, $data, $match, PREG_SET_ORDER); 

    for($i = 0; $i < $count; $i++) { 

     $count_args = count($match[ $i ]); 

     $args = array(); 

     // if any argouments, make an argouments array 
     if($count_args) { 
      // make array of argouments 
      for($arg_idx = 1; $arg_idx < $count_args; $arg_idx += 2){ 
       $args[ $match[ $i ][ $arg_idx ] ] = $match[ $i ][ $arg_idx + 1 ]; 
      } 
     } 
     echo 'name='.$args['name']; 
     echo '<br>'; 

     ob_start(); 
     call_user_func('test', $args); 
     $ret_func = ob_get_clean(); 
     $data = preg_replace($re, $ret_func, $data); 
    } 

    function test($arg) { 

     echo '<br>test(' . $arg['name'] . ')<br>'; 
    } 

    ?> 
</body> 

답변

0

는 처음에 나는 당신이 같은 ob_end_clean 포함시킬 필요하다고 생각 :

ob_start(); 
call_user_func('test', $args); 
$ret_func = ob_get_clean(); 
$data = preg_replace($re, $ret_func, $data); 
ob_end_clean(); 

을하지만 나는이 일을 기본적인 테스트 나 자신을 실행 :

<?php 
$i = 0; 
for($i=0; $i<10; $i++) 
{ 
    ob_start(); 
    test(); 
    $ret_func = ob_get_clean(); 
    echo '<p>' . $ret_func . '</p>'; 
    ob_end_clean(); //tried with this commented out as well 
    echo '<p>' . $ret_func . '</p>'; 
} 
function test() 
{ 
    echo rand(0,100); 
} 
?> 

을 그리고 만든 내가 ob_end_clean을 포함하면 차이가 없습니다. 따라서 실제로 루프의 각 반복에서 args 배열을 다시 작성하는 방법이 실제로 문제 일 수 있습니다.