2016-12-05 65 views
0

我的文件名是abc.php如何从PHP的注释行内容

<?php 
/* 
Template Name: mypage 
*/ 
?> 

所以, 如何让abc.php NAD和使用Template Name我的网页。 请帮我

+0

清除问题! Laravel或Wordpress? –

+0

任何一个laravel或wordpress –

+0

你想要模板名称,而应用程序运行,对不对? –

回答

1

你可以使用一些自定义的解析器(有几个可用)或反射,看看这个:

http://php.net/manual/en/reflectionclass.getdoccomment.php

或由svens在这里评论PHP read file comments NOT file content - forgotten

<?php 

    $source = file_get_contents("file.php"); 

    $tokens = token_get_all($source); 
    $comment = array(
     T_COMMENT,  // All comments since PHP5 
     T_ML_COMMENT, // Multiline comments PHP4 only 
     T_DOC_COMMENT // PHPDoc comments  
    ); 
    foreach($tokens as $token) { 
     if(!in_array($token[0], $comment)) 
      break; 
     // Do something with the comment 
     $txt = $token[1]; 
    } 

?>