Forum Moderators: coopster
Note that variables have "scope", which defines the places where the variable persists. A variable filled with your string in one script will appear empty when checked in another place - the basic scope of a PHP variable is inside it's own script.
Amateur coders used to declare every variable as "global" in scope, which made it easy to program, but caused all sorts of security problems.
Today variables are specifically "passed around" between scripts, using various methods, and (hopefully) with security checks all along the way.
Sounds like you would be well served with a function as suggested, but there is no need to put that function in a separate file for including... that just complicates things and introduces scope and nesting issues. Just place it inside your PHP file and call it as necessary.
If you canpost a sample code fragment it might be easier to help you out.