You cannot put php into a template. You need to put the php into a plugin and then you preregister the resulting variable for the variable you are going to use it in. It's not clear at all which template you are wanting to use this in so there is no way I can get more specific.
I can point you to this article about preregistering variables (near the end) -
[vB4] Rendering templates and registering variables - a short guide