Page 1 of 1

This is my situation...

Posted: Sat Nov 29, 2008 8:29 pm
by andreybs11
Impossible task

Hi everybody...I have never done a post but this time I have run out of patience for solving the situation. I want to share it with you...this is the problem:

1. My websites uses templates that are parse by a class. The parameters must be store in a var (string) so for example: to create a navigation bar all the stuff (all the html) must be store in a var

2. The content is also store in a var, so what I do is to create a simple file with some html and php and then tried to figure out how to read and most important PARSE the content into a string var. Here is why I called it "a problem"...if you read through the internet there are like 4 or 3 ways to do it using the "ob_get_contents()" but the problem with this is that it works like an engine....the things that happens inside the "ob_start()" and the "ob_clean()" are like "private", so all the stuff define before or after the engine is not considered...so all the objects, included vars, defined vars...EVERYTHING must be redefined and it doesn't have sense.

3. As good code developer obviously I use this process a lot of times...so I created a function that do all this just for not rewriting the same each time...but functions do not use public or defined vars...again the same problem...redefining variables is useless

4. I also tried to use "file_get_contents()" and then "eval()" to make the same but it also means that I need to redefined variables because they are on a function

5. [and most important maybe]...for some reason global variables are disable on my web hosting service thats why objects (like mysql connections, user info, shopping cart and others) are useless inside the function

...the word "redefine" stress me out :banghead: ...thats my problem :crazy:

NOTA: Please remember...the idea is to READ, PARSE the external file using internal and external variables and objects from other files and then STORE the result inside a variable as string

Any code suggestions (function) or any idea better idea of how to do what I want...

Re: This is my situation...

Posted: Sat Nov 29, 2008 10:47 pm
by omniuni
Um, I may need to read more carefully later, but to access a global variable, just precede it with "global"

in other words:

Code: Select all

 
$a = 4
 
function print_a(){
echo $a; //Doesn't do a thing
global $a;
echo $a; //now prints '4'
}
 
that help a bit?