Php Intro

  • Uploaded by: akirank1
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Php Intro as PDF for free.

More details

  • Words: 1,190
  • Pages: 23
PHP Introduction

History • • • • • •

Conceived in fall of 1994 PHP Version 1 in spring 1995 PHP Version 2 1995-1997 PHP Version 3 1997-2000 PHP Version 4 in Q2 2000 Development Team (339 people) – Community effort!

Statistics • As of July 1, 2001 • out of 31,299,592 Domains – PHP installed on 22.2% of all domains • source: Netcraft

• out of 1,984,899 Apache Servers surveyed – 846,501 (42.65%) PHP • source: SecuritySpace.com

Platforms Platforms (current): UNIX (all variants) Win32 (NT/W95/W98/W2000) QNX MacOS (WebTen) OSX OS/2

Platforms (experimental): OS/390 AS/400

BeOS Server Interfaces: Apache module (UNIX,Win32) CGI fhttpd module ISAPI module (IIS, Zeus) NSAPI module (Netscape iPlanet) Java servlet AOLServer Roxen module thttpd module

Server Interfaces Experimental): Apache 2.0 module

Embedding HTML Embedding SGML style: XML style: ASP style: <% code %> Javascript style: <script language="php"> code <TITLE>Search results for "" Traditional CGI programming #!/usr/bin/perl print "\n"; print " <TITLE>Search results for \"$query\"\n"; print "\n"; print "\n";

Switching modes Syntax and switching modes: You are using Internet Explorer You are not using Internet Explorer Output: You are not using Internet Explore

Form Handeling
Your name:
You age:
Action.php Hi . You are years old.

C-like Syntax 0) { echo "+"; } echo "$loop
\n"; } while(--$loop) { switch($i % 2) { case 0: echo "Even
\n"; break; case 1: echo "Odd
\n"; break; } } do { echo "$loop
"; } while (++$loop < 10); ?>

Data types Basic data types numbers (integers and real) Decimal 1234, Octal 0777, Hex 0xff strings Double-quoted "abc", single-quoted 'abc' booleans true,false Dynamic typing Don't have to declare types Automatic conversion done Example Output: 1006.5

Arrays Ordered Arrays: Associative Arrays: Manipulating Sorting: sort(), rsort(), ksort(), usort(), array_multisort() Traversal: reset(), end(), next(), each(), current(), key(), array_walk() Advanced: array_diff(), array_intersect(), array_merge(), array_merge_recursive(), array_slice(), array_splice() and lots more...

Array Manipulation 'mouse','dog'=>'mailman');?>

$v ) { echo "\$arr[$k] = $v
\n"; } ?> Output: $arr[0] = 1 $arr[1] = foo $arr[2] = 1.57 $arr[cat] = mouse $arr[dog] = mailman

current($arr) next($arr) current($arr) prev($arr) end($arr) current($arr) key($arr) reset($arr) each($arr) each($arr) each($arr)

1 foo foo 1 mailman mailman dog 1 array(0,1) array(1,'foo') array(2,1.57)

User functions Pass by reference Default values <TITLE>

OOP items[$artnr] += $num; } } ?> Inheriting a class with a Constructor owner = $name; } } ?> Invocation: add_item(170923, 2);?>

Date/Time Functions Date Format

Definition

a

Prints am or pm (lowercase

A

Prints AM or PM (uppercase)

d

Prints numerical day of month with leading zeros (01,02,….)

D

Prints day of week as 3 letter abbrev (Mon, Tue…)

F

Prints name of Month (January, February…)

h

Prints hout in 12 hour format

H

Prints hour in 24 hour format

i

Prints the minutes (00-59)

j

Prints day of month, no leading zeros

l

Prints day of week (Monday, Tuesday…)

m

Prints number of the month (1 to 12)

M

Prints 3 char, abbrev of month (Jan, Feb…)

S

Prints the suffix for day of month (st,nd,rd,th)

U

Prints number of seconds since Jan,1 1970 00:00:00

y

Prints year as two digits

Y

Prints year as 4 digits

z

Prints out day of the year (222,303,350)

Date/Time Functions $today = date(“M j, Y”);

// Feb 11, 2002

$today = date(“F jS, Y”);

// February 11th, 2002

$today = date(“D F d, h:ia”);

// Mon February 11, 3:30 pm

$today = date(“l F jS”);

// Monday February 11th

Date/Time functions

Sep 23, 2001 22:29:16

= 1) { printf("Dmitry has been charged for %dday%s!
\n",$days,$days==1?'':'s'); } else { $hours = $diff / 3600; if ($hours >= 1) { printf("Dmitry has been in jail for %d hour%s!
\n",$hours,$hours==1?'':'s'); } else { echo "Dmitry is speaking at DefCon
\n"; } } ?> Dmitry has been charged for 69 days!

Converts between calendars (Julian, Gregorian, Mayan, etc)

String Manipulation substr Fastipulation explode This string had delimiters.

C-like file functions Reading from a file: "; } ?> Reading from a URL: Writing to a file:

Sessions To start a session use session_start() and to register a variable in this session use session_register().
The $HTTP_SESSION_VARS array contains all the variables in the current session. If register_globals is enabled (which it is by default) then the session variables will automatically be available in the global namespace as well.

Database Support SQL: Adabas D Empress IBM DB2 Informix Ingres Interbase Frontbase mSQL Direct MS-SQL MySQL ODBC Ovrimos Oracle (OCI7,OCI8) PostgreSQL Raima Velocis Solid Sybase DB++

Other: dBase filePro (read-only) dbm (ndbm, gdbm, Berkeley db)

SQL Example PHP scripts that talk to databases all look similar to the code below. Connect to the database, select a database, send a query and loop through the results. \n"; echo "NameDescription\n"; while ($a = mysql_fetch_array($result)) { echo "$a[name]", "$a[descr]"; } echo ""; } else { echo "

Nothing to see here."; } ?>

DB Abstraction A database abstraction layer is bundled with PHP 4. In the example below, the only thing you would need to change to use a different database is the odbc word on the third line. prepare('SELECT * FROM comments'); $result = $db->execute($stmt); while($row = $db->fetchrow($result)) { while($row as $field => $value ) { echo "$field: $value
\n"; } } $db->disconnect(); ?>

New in Version 4 Better OO (syntax fixes, op. overloading, superclass ref.) Modular, self-contained extensions Database abstraction layer (ala Perl's DBI) Reference counting Thread safe core More server modules through SAPI foreach() Output buffering Support for a real debugger Support for caching compiled code Support for an optimizer Java ties


Related Documents

Intro Php
May 2020 4
Intro Php
October 2019 11
Php Intro
May 2020 9
Intro To Php
November 2019 16
Php Scripting Intro
May 2020 6

More Documents from "Khirulnizam Abd Rahman"

Javascript
May 2020 19
Ch8 Structures
April 2020 24
Ch4 Functions
April 2020 24
Cold Fusion Ii
May 2020 21