I am trying to migrate my site to PHP and use a WP theme on my site with out modifying the theme too much. So my problem is that I want to create a functions.php file like in WordPress that contains some code that can be called to load the header and footer of my sites theme from each page. Also I want to keep some constants in another file that will be used in my site for loading files from my sub-domains, getting the current year, etc. I have a basic get_file() function for loading files from my static content domain, But when I try to run it I get this:
Parse error: syntax error, unexpected T_FUNCTION in /home/s0urc3/public_html/includes/functions.php on line 4
Here are the contents of my functions.php and my constants.php:
functions.php
<?php
include('constants.php')
/*Gets a file from the domain http://files01.s0urc3.ismywebsite.com/*/
function get_file($file)
{
FILE_ROOT + $file
}
get_file(images/bg.jpg)
?>
constants.php
<?php
/* CONSTANTS*/
define(FILE_ROOT, "http://files01.s0urc3.ismywebsite.com/")
define(HOME, "http://s0urc3.ismywebsite.com/")
define(BLOG_HOME, "http://blog.s0urc3.ismywebsite.com/")
define(FORUMS_HOME, "http://forums.s0urc3.ismywebsite.com/")
define(YEAR, getdate(year))
/*define(FILE_ROOT, "http://files01.s0urc3.ismywebsite.com/")*/
?>
Any and all help would be much appreciated.
You have virtually no lines free of syntax errors. You will never get anywhere muddling your way forward this way. Find a tutorial and learn PHP before trying to port your code.
Specifically:
In PHP, as in other C-style languages, your statements must end with semicolons:
Your uses of
defineare wrong. The symbol to define must be passed todefine()as a string before it can be used as a symbol:Strings must be enclosed in either single quotes or double quotes:
Values must be explicitly returned from functions via the
returnkeyword, and strings are concatenated using the dot.operator:And a note on style: You’ve commented
get_fileas ‘getting a file’, which it definitely doesn’t do. All it does is return the fully-qualified URL of the relative URL you pass it. Your function names and comments should strive to clearly tell you what they do. In the case of such a short utility function, I’d go for something very short: