Praveen Puglia
Praveen Puglia

Reputation: 5631

Automation of a snippet insertion process in php

Well, I have no idea of this and how to do this but its making me go crazy. so here is the thing..

suppose i have this piece of code in say 20 files.

while(//some_condition):
    .....
   // do something here
    .....
endwhile;

Now i need to wrap this loop within a conditional tag say something like this.

if(// condition_for_if ):
    while(//some_condition):
        .....
        //do something here
        .....
    endwhile;
endif;

The problem is, its a super tedious job if you have this in large number of files, sometimes with multiple instances within one single file.

How can i automate the process? can i write a script in php to do that? At first the idea of installer scripts like the one wordpress has came to my mind but i clearly understood that it cannot be done that way.

What to do?

Upvotes: 0

Views: 101

Answers (1)

Matt Whitehead
Matt Whitehead

Reputation: 1811

Put your code into a function in it's own separate file, include it in the scripts where you use it, and simply call the function where needed, passing along any required arguments. Or you could even make the separate file a class and do it that way.

Upvotes: 1

Related Questions