2016-12-05 62 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]; 
    } 

?>