Our next program will be a more complexed variable program, using a verse that is repeated two times. The song chosen for this task is "Do you want to know a secret" by The Beatles.
As we have noted when we wrote the Using a variable php program, a variable is a holder for information in a computer's memory.
Similar to the previous two programs, the PHP code uses the <? and ?> special tag. We then use a special technique provided by PHP when writing this program. We start by assigning a value to the $verse variable as shown below:
$verse = <<<HERE
The <<<HERE segment signifies that there is a multi-line string. Once the verse text is written, the ending phrase HERE; is placed on a line by itself.
As demonstrated in the previous programs, we used notepad a plain text editor and stored the program on our web server, "C:\Wampserver2\www."
The steps to writing a PHP program are outlined below:
1. Select and click "Start."
2. Select and click "All Programs."
3. Select and click "Accessories."
4. Select and click "Notepad."
5. Type the HTML and PHP exactly as shown below.
<html>
<head>
<title>Do you want to know a secret by the Beatles</title>
</head>
<body><h1>Do you want to know a secret</h1>
<h3>Demostrates use of long variables<h3>
You'll never know how much I really love you<br>
You'll never know how much I really care<br>
<br> <br>
<?php
$verse = <<<HERE
Listen<br>
Do you want to know a secret<br>
Do you promise not to tell, whoa oh, oh<br>
<br>
Closer<br>
Let me whisper in your ear<br>
Say the words you long to hear<br>
I'm in love with you<br>
<br><br>
HERE;
print "<h3>Verse 1:</h3>";
print $verse;
print "<h3>Verse 2:</h3>";
print $verse;
?>
I've known the secret for a week or two<br>
Nobody knows, just we two<br>
<br> <br>
<?php
print "<h3>Verse 3:</h3>";
print $verse;
?>
</body></html>
6. Once you have type the entire program, Select "File," "Save As," and then go to the webroot of your server. For example, C:\Wampserver2\www. Type Filename, "listendoyou.php," and then Select "Save."
7. Use your browser to view the tips.php program. The steps are outlined below:
1.Select and click "Start. "
2.Select and click "All Programs."
3.Select and click "Internet Explorer."
4.Locate the Web Address Field, near the top-left of the Internet Explorer window and type in the Web address of the listendoyou.php program, "http://localhost/listendoyou.php," then enter.
The listendoyou.php program will be displayed.















Comments