Learning PHP and MySQL

Chapter 3 Code

Source code from the 3rd chapter.

Wednesday, August 09, 2006

Example 03-01 All you need to start with PHP is a simple HTML document

<html>
<
head>
<
title>Hello  World</title>
</
head>
<
body>
<
p>I  sure  wish  I  had  something  to  say.</p>
</
body>
</
html>

Posted by admin on 08/09 at 03:22 PM
Chapter 3 Code • (3) Comments • (1758) TrackbacksPermalink

Thursday, July 06, 2006

Example 03-02 Adding PHP Code to an HTML File

<html>
    <
head>
        <
title>Hello World</title>
    </
head>
    <
body>
        echo(
"<p>Now I have something to say.</p>");
    </
body>
</
html>

This should be saved out with the .php extension, not the .html extension.

Posted by krautgrrl on 07/06 at 01:41 PM
Chapter 3 Code • (137) Comments • (1862) TrackbacksPermalink

Example 03-03 Calling echo() and print()

<html>
    <
head>
        <
title>Hello World</title>
    </
head>
    <
body>
        <?
php

        
echo ("Hello world!<br />");
        print (
'Goodbye.<br />');
        print 
'Over and out.';

        
?> 
    </body>
</html>

Posted by krautgrrl on 07/06 at 02:38 PM
Chapter 3 Code • (4) Comments • (2310) TrackbacksPermalink

Wednesday, August 09, 2006

Example 03-04 The HTML markup produced by the PHP code

<html>
<
head>
<
title>Hello  World</title>
</
head>
<
body>
Hello  world!<br  />Goodbye.<br  />Over  and  out.
</
body>
</
html>

Posted by admin on 08/09 at 03:23 PM
Chapter 3 Code • (26) Comments • (4349) TrackbacksPermalink

Wednesday, July 19, 2006

Example 03-05 Using comments to make your code easier to read

<html>
<
head>
<
title>Hello  World</title>
</
head>
<
body>
<?
php

//  A  single  line  comment  could  say  that  we  are  going  to
//  print  hello  world.

/*  This  is  how  to  do  a
multi-line  comment  and  could  be  used to  comment  out  a  block of  code  */

echo("Hello  world!<br  />");
print(
'Goodbye.<br  />');

?>
</body>
</html>

Posted by krautgrrl on 07/19 at 03:37 PM
Chapter 3 Code • (1) Comments • (368) TrackbacksPermalink

Wednesday, August 09, 2006

Example 03-06 Reassigning a variable

<?php
$age  
=  30;
$age  =  31;
echo  
$age;
?>

Posted by admin on 08/09 at 03:25 PM
Chapter 3 Code • (2) Comments • (204) TrackbacksPermalink

Wednesday, July 19, 2006

Example 03-07 The default handling of variable scope

<?php

//  define  a  function function  birthday(){
//  Set  age  to  1
$age  =  1;
}

//  Set  age  to  30
$age  =  30;

//  Call  the  function
birthday();

//  Display  the  age echo  $age;

?>

Displays:

30

Posted by krautgrrl on 07/19 at 03:38 PM
Chapter 3 Code • (5) Comments • (788) TrackbacksPermalink

Example 03-08 Using a global variable changes the result

<?php

//  Define  a  function function  birthday(){
//  Define  age  as  a  global  variable
global  $age;

//  Add  one  to  the  age  value


//  set  age  to  30
$age  =  30;

//  Call  the  function birthday();

//  Display  the  age echo  $age;

?>

Displays:

31

Posted by krautgrrl on 07/19 at 03:40 PM
Chapter 3 Code • (3) Comments • (97) TrackbacksPermalink

Example 03-09 A static variable remembering its last value

<?php
//  Define  the  function function  birthday(){
//  Define  age  as  a  static  variable static  $age  =  0;

//  Add  one  to  the  age  value
$age  =  $age  +  1;

//  Print  the  static  age  variable
echo  "Birthday  number  $age<br  />";
}

//  Set  age  to  30
$age  =  30;

//  Call  the  function  twice birthday();
birthday();

//  Display  the  age
echo  "Age:  $age<br  />";

?>

Displays:

Birthday number 1
Birthday number 2
Age:  30

Posted by krautgrrl on 07/19 at 03:41 PM
Chapter 3 Code • (4) Comments • (654) TrackbacksPermalink

Example 03-10 PHP_SELF being used with a file called test.php

<?php
echo  $_SERVER["PHP_SELF"];
?>

Outputs:

/test.php

Posted by krautgrrl on 07/19 at 03:42 PM
Chapter 3 Code • (4) Comments • (503) TrackbacksPermalink

Example 03-11 Working with strings

<?php
$my_string  
=  "Margaritaville  -  Suntan  Oil  Application!";
echo  
"Margaritaville  -  Suntan  Oil  Application!";
?>

Posted by krautgrrl on 07/19 at 03:43 PM
Chapter 3 Code • (4) Comments • (1002) TrackbacksPermalink

Example 03-12 Using a variable in a string definition

<?php
$my_string  
=  "Margaritaville  -  Suntan  Oil  Application!";
echo  
"Time  for  $my_string";
?>

Posted by krautgrrl on 07/19 at 03:43 PM
Chapter 3 Code • (0) Comments • (3647) TrackbacksPermalink

Example 03-13 Single quotes used in a string assignment

<?php
$my_string  
=  'Margaritaville  -  Suntan  Oil  Application!';
echo  
$my_string;
?>

Posted by krautgrrl on 07/19 at 03:44 PM
Chapter 3 Code • (26) Comments • (150) TrackbacksPermalink

Example 03-14 Various special characters in string assignments

<?php
$newline  
=  "A  newline  is  \n";
$return  =  "A  carriage  return  is  \r";
$tab  =  "A  tab  is  \t";
$dollar  =  "A  dollar  sign  is  \$";
$doublequote  =  "A  double-quote  is  \"";
?>

Posted by krautgrrl on 07/19 at 03:45 PM
Chapter 3 Code • (3) Comments • (278) TrackbacksPermalink

Example 03-15 Using echo with special characters

<?php
//  This  won't  work  because  of  the  quotes  around  specialH2!
echo  "<h2  class="specialH2">Margaritaville!</h2>";
?>

Posted by krautgrrl on 07/19 at 03:45 PM
Chapter 3 Code • (2) Comments • (2037) TrackbacksPermalink
Page 1 of 2 pages  1 2 >

Statistics

This page has been viewed 374233 times
Page rendered in 0.2019 seconds
Total Entries: 224
Total Comments: 16
Total Trackbacks: 307338
Most Recent Entry: 09/27/2006 12:39 pm
Most Recent Comment on: 10/26/2007 10:00 am
Total Members: 2
Total Logged in members: 0
Total guests: 13
Total anonymous users: 0
Most Recent Visitor on: 02/06/2012 06:33 am
The most visitors ever was 1103 on 11/20/2007 12:50 pm

Referrers

Powered by ExpressionEngine