I'm trying to create a script to extract the variables from a file on the same server.
The problem is, I don't know what else is going to be in the file all of the time (the script is for other people to use), so I don't really want to load all of the contents or execute any of the code.
I've thought of using file_get_contents rather than anything like require or include, but I'm stuck... is there a way to parse all of the variables within the string? Alternatively, is there a "safe" way to include files?
Many thanks, James
file_get_contents + preg_match
You'll need some crafty regex to go along with it.
Why don't you put all the variables in a third file, then include them in the other two files?
What you are trying to do sounds dangerous, especially if by "for other people to use" you mean others can write those files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With