Returning HTML Strings in PHP?

J'sylve

New member
Okay well I have a hw assignment but for some reason the code I wrote isn't working (as always)

Here's the instructions:

Write a function named getHeader() that will be an improvement to the function display_company_name() from a previous lab. The function getHeader() will return an HTML string that contains a table and the company name in a large centered headline font. Use two (2) parameters to the function, pass $company_name for the text to display and another parameter to set the color of the table. DO NOT use the print command in this function, return a string containing the HTML.


Write a function named getFooter() that will be an improvement to the function display_company_address() from a previous lab. The function getFooter() will return an HTML string that contains a table and the company name, address and city/state/zip in a small/normal centered font. Use a parameter to the function to set the color of the table and the global variables $company_name, $company_address, etc. for the text to display. DO NOT use the print command in this function, return a string containing the HTML.

Here's my code:


/************* global variables ******************************/
$company_name = "Vacations Site";
$company_address ="1234 Abc Ave. Los Angeles, CA 90015";

/************* end global variables **************************/


display_company_name("company_name"); // use parameter to pass input to function


function display_company_name($local_name) {
$local_name = "Vacations Site";
print "<H1>$local_name </H1>";
}


function display_company_address(){
global $company_name;
global $company_address;
print "<strong><u>$company_name, $company_address</u></strong>";

}


function getHeader() {
$data = "<TABLE BGCOLOR='GREEN' WIDTH='100%'><TR><TD ALIGN='CENTER'>";
$data .= "<H1>$company_name</H1>"; // the .= adds this HTML to the HTML above
$data = $data . "</TD></TR></TABLE>"; // same as .= just another way
return $data; // send the HTML back to the caller
}


function getFooter() {
$data = "<TABLE BGCOLOR='GREEN' WIDTH='100%'><TR><TD ALIGN='CENTER'>";
$data .= "<H1>$company_name, $company_address<br /></H1>"; // the .= adds this HTML to the HTML above
$data = $data . "</TD></TR></TABLE>"; // same as .= just another way
return $data; // send the HTML back to the caller
}


print getHeader();

print getFooter();



What am I doing wrong? and why is it just giving me a comma within the table when i "print" the function
my professor wrote the single quotes for the table bgcolor. I don't understand why my code isn't working. There has to be something wrong here.
 
Back
Top