Learning PHP and MySQL

Thursday, August 03, 2006

Example 05-01 The ubiquitous Hello world!

<?php
echo  ("Hello  world!");
?>

Posted by krautgrrl on 08/03 at 08:16 AM
Chapter 5 Code • (0) Comments • (1) TrackbacksPermalink

Example 05-02 Displaying information about the PHP environment

<?
php phpinfo();
?>

Posted by krautgrrl on 08/03 at 08:17 AM
Chapter 5 Code • (2) Comments • (2) TrackbacksPermalink

Example 05-03 Creating an md5 signature

<?php
$mystring  
=  "mystring";
$signature  =  md5($mystring);
echo  
$signature;
?>

Posted by krautgrrl on 08/03 at 08:18 AM
Chapter 5 Code • (0) Comments • (1) TrackbacksPermalink

Example 05-04 Using the string capitalization functions

<?php
//  Capitalize  a  string 
function  capitalize(  $str  )
{
  
//  First,  convert  all  characters  to  lower  case
  
$str  =  strtolower($str);
  
//  Second,  convert  the  first  character  to  upper  case
  
$str{0}  =  strtoupper($str{0});
  echo  
$str;
}
capitalize
("hEllo  WoRld!"  );
?>

Posted by krautgrrl on 08/03 at 08:18 AM
Chapter 5 Code • (1) Comments • (1) TrackbacksPermalink

Example 05-05 Creating a capitalize function with a default parameter $each

<?php
//  Capitalize  a  string  or  the  first  letter  of  each  word 
function  capitalize(  $str,  $each=TRUE  )
{
  
//  First,  convert  all  characters  to  lower  case
  
$str  =  strtolower($str);
  if  (
$each  ===  TRUE)  {
    $str  
=  ucwords  ($str);
  
}  else  {
    $str  
=  strtoupper($str);
  
}
  
echo  ("$str  <br>");
}
capitalize
("hEllo  WoRld!");
echo  (
"Now  do  the  same  with  the  each  parameter  set  to  FALSE.<br>");
capitalize("hEllo  WoRld!",FALSE);
?>

Posted by krautgrrl on 08/03 at 08:19 AM
Chapter 5 Code • (1) Comments • (1) TrackbacksPermalink

Example 05-06 Modifying capitalize to take a reference parameter

<?php
function  capitalize(  &$str,  $each=true  )
{
  
//  First,  convert  all  characters  to  lower  case
  
$str  =  strtolower($str);
  if  (
$each  ===  true)  {
    $str  
=  ucwords($str);
  
}  else  {
    $str{0}  
=  strtoupper($str{0});
  
}
}
$str  
=  "hEllo  WoRld!"
capitalize(  &$str  ); 
echo  
$str;
?>

Posted by krautgrrl on 08/03 at 08:19 AM
Chapter 5 Code • (0) Comments • (2) TrackbacksPermalink

Example 05-07 A sample include file called add.php

<?php
function  add(  $x,  $y  )
{
  
return  $x  +  $y;
}
?>

Posted by krautgrrl on 08/03 at 08:20 AM
Chapter 5 Code • (0) Comments • (247462) TrackbacksPermalink

Example 05-08 Using the include function

<?php
include('add.php');
echo  
add(2,  2);
?>

Example 5-9. Using include_once to include a file
<?php 
include_once('add.php'); 
include_once(
'add.php'); 
echo  
add(2,  2);
?>

Posted by krautgrrl on 08/03 at 08:20 AM
Chapter 5 Code • (0) Comments • (1) TrackbacksPermalink

Friday, August 18, 2006

Example 05-09 Using include_once to include a file

<?php
include_once('add.php');
include_once(
'add.php');
echo  
add(2,  2);
?>

Posted by admin on 08/18 at 10:00 AM
Chapter 5 Code • (0) Comments • (294) TrackbacksPermalink

Thursday, August 03, 2006

Example 05-10 Creating an object from the Cat class

<?php
class  Cat  {
}

$fluffy  
=  new  Cat();
echo  
"Fluffy  is  a  new  ".gettype($fluffy)."!";
?>

Posted by krautgrrl on 08/03 at 08:21 AM
Chapter 5 Code • (0) Comments • (30434) TrackbacksPermalink

Example 05-11 Creating the Cat constructor

<?php
class  Cat  {
//  Constructor 
  
function  Cat()  {
  }
}
?>

Posted by krautgrrl on 08/03 at 08:21 AM
Chapter 5 Code • (0) Comments • (0) TrackbacksPermalink

Example 05-12 Using the PHP 5 style constructor

<?php
class  Cat  {
//  Constructor
__construct(){
  }
}
?>

Posted by krautgrrl on 08/03 at 08:21 AM
Chapter 5 Code • (1) Comments • (100) TrackbacksPermalink

Example 05-13 Defining three member functions for Cat

<?php
Class  Cat  {
  
//  Constructor 
  
function  Cat()  {
  }

  
//  The  cat  meows 
  
function  meow()  
    
echo  "Meow...";
  
}

  
//  The  cat  eats 
  
function  eat()  
    
echo  "*eats*";
  
}

  
//  The  cat  purrs 
  
function  purr()  
    
echo  "*Purr...*";
  
}
}
?>

Posted by krautgrrl on 08/03 at 08:22 AM
Chapter 5 Code • (1) Comments • (1) TrackbacksPermalink

Example 05-14 Creating a new object without saving the reference

This is: Creating a new object without saving the reference, then creating an object to keep around.

<?php
new  Cat;
//the  Cat  object  cannot  be  accessed  since  its  reference  wasn’t  saved

$myCat=new  Cat;
//this  time  we've  kept  the  new  Cat  object  available
?>

Posted by krautgrrl on 08/03 at 08:22 AM
Chapter 5 Code • (0) Comments • (0) TrackbacksPermalink

Example 05-15 Adding the $age variable to Cat

<?php
class  Cat  {
  
//  How  old  the  cat  is 
  
var  $age;
}
?>

Posted by krautgrrl on 08/03 at 08:23 AM
Chapter 5 Code • (0) Comments • (0) TrackbacksPermalink
Page 4 of 15 pages « First  <  2 3 4 5 6 >  Last »

Statistics

This page has been viewed 187006 times
Page rendered in 0.4646 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: 10
Total anonymous users: 0
Most Recent Visitor on: 01/06/2009 07:50 pm
The most visitors ever was 1103 on 11/20/2007 12:50 pm

Referrers

Powered by ExpressionEngine