I am not getting required output

Asked By 0 points N/A Posted on -
qa-featured

Hi,

Study the following code :

<script language="php">
# Set a few variables
$site_title = "PHP Recipes";
$bg_color = "red";
$user_name = "Chef Luigi";
</script>
<html>
<head>
<title><script language="php"> print $site_title; </script></title>
</head>
<body bgcolor="<%=print $bg_color; %>" >
<?=$site_title; ?>
<?
# Display an intro. message with date and user name.
print "
PHP Recipes | ".date("F d, Y")." <br>
Greetings, $user_name! <br>
";
?>
</body>
</html>

Output :

PHP Error-Greetings, $user_name

There is not a correct output I got. I want to get the following output :
PHP Recipes PHP Recipes | August 26, 2011
Greetings, Chef Luigi!

I Think there is a small problem in my script.

What is the problem?

Solve anybody knows.

SHARE
Best Answer by Josephm
Best Answer
Best Answer
Answered By 0 points N/A #118694

I am not getting required output

qa-featured

First of all, I would like to inform you that the date function you have used will not work on localhost.

Secondly, this is the reviewed code I have written and I have tested this on server too, this is working completely fine.

<script language="php">
# Set a few variables
$site_title = "PHP Recipes";
$bg_color = "red";
$user_name = "Chef Luigi";
</script>
<html>
<head>
<title><script language="php"> print $site_title; </script></title>
</head>
<body bgcolor="<?php print $bg_color; ?>" >
<?php print $site_title; ?>
<br />
<?
# Display an intro. message with date and user name.
$date1 = date('l jS of F Y h:i:s A');
echo ("PHP Recipes | ".$date1. "<br />");
echo ("Greetings," .$user_name. "<br />");

?>
</body>
</html>

Preview:

PHP recipes message with date and user name
Answered By 0 points N/A #118695

I am not getting required output

qa-featured

This is current code and also check it. You can use "echo " to print and also echo but you have to save your file as .php than it allow you work fine.

I check one Google chrome and as well IE 9.
<script language="php">
# Set a few variables
$site_title = "PHP Recipes";
$bg_color = "red";
$user_name = "Chef Luigi";
</script>
<html>
<head>
<title><script language="php"> print $site_title; </script></title>
</head>
<body bgcolor="<%=print $bg_color; %>" >
<?=$site_title; ?>
<?
# Display an intro. message with date and user name.
print "
PHP Recipes | ".date("F d, Y")." <br>
Greetings, $user_name! <br>
";
?>
</body>
</html>

Check in IE 9

PHP recipes
 
By using "echo"
<script language="php">
# Set a few variables
$site_title = "PHP Recipes";
$bg_color = "red";
$user_name = "Chef Luigi";
</script>
<html>
<head>
<title><script language="php"> print $site_title; </script></title>
</head>
<body bgcolor="<%=print $bg_color; %>" >
<?=$site_title; ?>
<?
# Display an intro. message with date and user name.
echo "
PHP Recipes | ".date("F d, Y")." <br>
Greetings, $user_name! <br>
";
?>
</body>
</html>
Declaring php
Three different way to write your code in php
<?
include(databaseconnection.php);
?>
<?php
echo "Problem solved";
php?>
<script language="php">
you write your code here.
</script>
Answered By 5 points N/A #118696

I am not getting required output

qa-featured

<?Php
$file = $_SERVER['DOCUMENT_ROOT'] . "/text.txt"; //Path to your *.txt file
$contents = file($file);
$string = implode($contents);

echo $string;
?>

Related Questions