开发者

Can any body help to split php source code

开发者 https://www.devze.com 2022-12-22 17:25 出处:网络
can any body help me on separating this example of data that i need to parse and seperate text just like PHPDoc. It is PHP source code.

can any body help me on separating this example of data that i need to parse and seperate text just like PHPDoc. It is PHP source code.

The example string :

function one_to_tree() {
        //bla bla bla   
    return FALSE;
}


function two_to_tree() {
        //bla bla bla   
    return FALSE;
}


function three_to_tree() {

       if ($sample){ //bla bla bla   } 
    return FALSE;
}

can anybody help me how to seperate above string based on "function" word and create and array. Thank you开发者_运维知识库


I think you are looking for token_get_all().

This function uses the PHP parser to split PHP source code into tokens. I think it's safe to say it's the most reliable method of parsing PHP code - if it's usable for whatever you are planning to do.

An example from the manual:

$tokens = token_get_all('<?php echo; ?>'); 

Results in

array(
  array(T_OPEN_TAG, '<?php'), 
  array(T_ECHO, 'echo'),
  ';',
  array(T_CLOSE_TAG, '?>') 
);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号