mercredi 24 juin 2020

how to get methods code from a file in php without removing back to line and tabs

i m trying to make a function that can read a file and return the name of methods and their correspond code " similar to reflection but reflections remove return to line and tabs and i wanna keep them to show them out in the editor . i tried this but it removes the spaces and back to line

function get_sourcecode($classname, $methodename) {

$func = new ReflectionMethod($classname, $methodename);
$filename = $func->getFileName();
$start_line = $func->getStartLine() - 1; // it's actually - 1, otherwise you wont get the function() block
$end_line = $func->getEndLine();
$length = $end_line - $start_line;

$source = file($filename);
$body = implode("", array_slice($source, $start_line, $length));

return $body;

}





Aucun commentaire:

Enregistrer un commentaire