Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP regular expression search for includes, then write the includes where it found them

I have this script (well commented!) that searches files in a folder using regular expressions, removes comments and HTML, but leaves the tag intact. I would want this script to do the same, but instead of leaving tag's intact, it need to print the include it finds to file.

For example:

<!--TPFILE--><?include '/module/menu.html';?><!--TPFILEEND-->

So the goal is to print out the HTML from menu.html to where the regular expression found the include. I'm very new to PHP but understand the basics, though, I'm stuck on this one.

EDIT: I found a solution, it's posted as an answer below.

like image 868
t.mikael.d Avatar asked Nov 14 '22 22:11

t.mikael.d


1 Answers

Is this syntax required : <?include '/module/menu.html';?>? Could you replace this with <?php include '/blah/foo.php';?>? If so, you could either directly include the file, or use token_get_all() to split the HTML up in to PHP chunks and normal string (HTML) output.

like image 157
Robin Avatar answered Dec 18 '22 10:12

Robin