Hello there!
I would like to make a module, which would parse the whole php file for my own code and possibly insert the text in the different places in it. It would check for the other included modules, which would do the actual parsing, each module for it's own purpose. Now I'm a bit indecisive how to start the whole thing. It somehow seems to me the approach with the reading the file, parsing it and then printing it out is very time consuming (if I'd do it for each article I have). These articles probably won't have the php code, so I probably won't need to use the eval() function (just the plain "echo" output). What do you guys think about this? Is this approach (reading / parsing / writing) totally stupid and time consuming or should I give it a go? Are there already some better approaches (I'm pretty new to php)?
Thanks.
Parsing the file before including it
Moderator: General Moderators
- nutcracker
- Forum Newbie
- Posts: 3
- Joined: Sat Oct 13, 2007 4:00 am
- Location: Croatia
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Modifying a script on-the-fly? Probably not a good idea. This needs some rethinking.
For example, one could pass data to the class/functions/pie-bits with details that would allow them to choose some generalized code for execution.
It sounds more like you're talking about templating. Look into Template Lite if you are.
For example, one could pass data to the class/functions/pie-bits with details that would allow them to choose some generalized code for execution.
It sounds more like you're talking about templating. Look into Template Lite if you are.
- nutcracker
- Forum Newbie
- Posts: 3
- Joined: Sat Oct 13, 2007 4:00 am
- Location: Croatia
Thank you for your answer.
I have checked out Template Lite and Smarty, before that I checked some tutes about templating to even have a bit of clue what I'm looking at. I didn't have much time for checking it (as I work the whole day), but even this small amount of time looking into it brought me doubts if this is the stuff I'm looking for. I will most definitely have a detailed look into it when I find a bit of time. Thanks for that info.
Let me be more specific on my goals. I'd like to accomplish two things:
The first would be to make a module, which would detect all the headers (<hX>...</hX>) in my article, and then generate the code for the table of contents at the beginning of the file. It's links would point to the <a name=...> tags automatically positioned above every header.
The second is the module, which would check my code for some special tags (let's say [ref="1"]) and according to the tag would generate a reference section at the end of the page from the list of references situated in a mysql table. So the reader would see the reference numbers in the text placed in the square brackets, and in the end of the document would be a list of all the used references (not all the references from that table).
Note that those articles wouldn't contain ANY php code, just the html tags for the layout, connected with the external css files and the contents of an article. So I wouldn't actually be modifying any PHP script, just HTML.
As I still don't know about the powers of templating, I'm not sure if I could do this with it. If you have any idea how to do it, please give me some hints how to start the right way. I'll do the rest
. Thanks.
I have checked out Template Lite and Smarty, before that I checked some tutes about templating to even have a bit of clue what I'm looking at. I didn't have much time for checking it (as I work the whole day), but even this small amount of time looking into it brought me doubts if this is the stuff I'm looking for. I will most definitely have a detailed look into it when I find a bit of time. Thanks for that info.
Let me be more specific on my goals. I'd like to accomplish two things:
The first would be to make a module, which would detect all the headers (<hX>...</hX>) in my article, and then generate the code for the table of contents at the beginning of the file. It's links would point to the <a name=...> tags automatically positioned above every header.
The second is the module, which would check my code for some special tags (let's say [ref="1"]) and according to the tag would generate a reference section at the end of the page from the list of references situated in a mysql table. So the reader would see the reference numbers in the text placed in the square brackets, and in the end of the document would be a list of all the used references (not all the references from that table).
Note that those articles wouldn't contain ANY php code, just the html tags for the layout, connected with the external css files and the contents of an article. So I wouldn't actually be modifying any PHP script, just HTML.
As I still don't know about the powers of templating, I'm not sure if I could do this with it. If you have any idea how to do it, please give me some hints how to start the right way. I'll do the rest
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
A simple regular expression of the data on the fly to build the table of contents is as simple as
Code: Select all
preg_match_all('#<hX>(.*?)</hX>#im', $input, $matches);
echo '<pre>';
print_r($matches[1]);- nutcracker
- Forum Newbie
- Posts: 3
- Joined: Sat Oct 13, 2007 4:00 am
- Location: Croatia