Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何读取.php文件并在php文件中显示标记区域_Php_Variables_Directory_Substring - Fatal编程技术网

如何读取.php文件并在php文件中显示标记区域

如何读取.php文件并在php文件中显示标记区域,php,variables,directory,substring,Php,Variables,Directory,Substring,可能重复: 我需要一些帮助来制作一个可以读取给定目录中任意数量的.php文件的代码,查找这些页面上的“标记”区域,例如: <? #### # ((((((Test Area))))) #### ?> (some html) <? #### # ((((((Test Area2))))) #### ?> 我会研究Smarty模板系统 基本上,您是在长字符串中进行正则表达式搜索。因此,首先获取字符串: $template = file_get_contents('my

可能重复:

我需要一些帮助来制作一个可以读取给定目录中任意数量的.php文件的代码,查找这些页面上的“标记”区域,例如:

<? ####
# ((((((Test Area)))))
#### ?>

(some html)

<? ####
# ((((((Test Area2)))))
#### ?>

我会研究Smarty模板系统

基本上,您是在长字符串中进行正则表达式搜索。因此,首先获取字符串:

$template = file_get_contents('myfile.tpl.php');
然后使用您选择的正则表达式方法进行搜索。可能使用如下php方法:

$search = "/^\{\{\{\{\{somePlaceholder\}\}\}\}\}/";
$replace = $yourNode;    
$scrubbedTemplate = preg_replace($search, $replace, $template);
print $scrubbedTemplate;

注意:我的直觉告诉我,你的做法是错误的。MVC框架包含模板的方式可能更好。实际上,他们会执行一次include_('file.tpl.php'),并且在调用include之前,他们会在该文件中包含真正的php变量,这些变量只有值。

那么您正在使用称为php的模板系统来运行您自己的元模板系统?Yo dawg…@MarcB我教你liek模板系统,所以我在ur模板系统中创建了一个模板系统。让脚本扫描.php文件目录,查看每个文件,在标记标识符区域内获取唯一名称,并将它们插入mysql表,会更容易吗?