Top-Rated Free Essay
Preview

Noman Haider

Powerful Essays
1703 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Noman Haider
PHP Quick Reference Card1.02 string - single byte character sequence. See below.
__DIR__
Variables that have not been assigned a value or have been unset contain the special value NULL. A NULL __CLASS__ assignment to an object variable destroys the object.
__METHOD__
Explicit typecasts are rarely needed in PHP. If required Magic constants use the code inclusion. Copyright©, 2008 BrandsPatch LLC

$x = (#)$y; - where # is one of bool, float, int or string.

Operators

http://www.explainth.at

Operator

Color key on Page 4

Code Structure

Example

Result

3+ 2

5

.

'Explain'.'That!'

'ExplainThat!'

/ «*»

3/2

1.5

%

7%4

3

$s = 'Hello from ';

=

$i = 2

$i set to 2

echo $s;

$i = 2;
$i+=1;

3

$site = 'ExplainThat'; function sayHello(){

//single line comment
}

+= «-=»

Variable Management
Purpose

Return Value

empty

Check if empty?

boolean

floatval

Convert to float

float

.=

s.='That!'

'ExplainThat!'

$s = 'Hello from ';

==1

3=='3'
3==3
3==2

true true false

get_defined_vars List all variables

array

gettype

Verify data type

string1

intval

Convert to int

integer

is_#2

Verify data type

boolean

Stringify for storage string

settype3

Set data type

boolean

strval

function sayHelloEx(){

echo $s.$site;

Method name as class:methodname in included files are evaluated prior to

serialize

s = 'Explain';

global $site;

Current class name

Function

+ «-»

Reusing Code

would cause the contents of mycode.php to be merged | into the current file. Failure to find mycode.php results in a warning. require behaves similarly but throws a fatal ^ error. The #_once versions prevent function redefinition.
~
All labels1 in PHP bear the form $name. name can consist of upper & lowercase letters a-z, extended
ASCII characters from 0x7F to 0xFF, the underscore character, _ and numbers. The first character cannot be a number. Names are case sensitive. $this is a predefined read only variable used to refer to the current object context. There are no limits on name length. Names are case sensitive.
1 Strings used to identify constants, functions, variables & Heredoc

Arrays
Arrays are used to store sequences of related values in a tabular format. PHP has 5 ways of defining an array

$lamp[]='MySQL';$lamp[]='PHP';

The include, require, include_once and require_once $i = 2;$j = 5; keywords facilitate the reuse of PHP code. For instance
&
$i & $j include 'mycode.php';

Nomenclature Rules

-

1 array, boolean, integer, double, string or object
2 # is one of array, bool, float, int, null, object, scalar, string
3 second parameter is a string. See note 1 above
4 behavior inside a function depends on nature of variable being unset

2

$i | $j
$i ^ $j

5

~$i

-3



$i 'LINUX','A'=>'Apache',

7

'M'=>'MySQL','P'=>'PHP');
$lamp = array('LINUX','Apache',
'MySQL','PHP');
$lamp = array();
$lamp[1]='LINUX';$lamp[2]='Apache';
$lamp[3]='MySQL';$lamp[4]='PHP';1

$i = 2;$j = 5

Visibility & Scope
!
($i==2) && !($j true
%2 == 0)
Variables in PHP generally have a single scope – i.e they are always visible. However, user defined functions 1 called loose comparison; 2 called strict comparison have their own local scoping context – i.e. do not have 3 evaluates after use 4 evaluates before use access to variables defined outside the function. A
Constants
reference to $site in sayHello would merely create a define($name,$value,[$ci]) new empty local variable called $site. To access such is used to define a constant named $name with the variables do one of the following scalar value $value. Case insensitive if $ci = TRUE.
Use the global keyword as in sayHelloEx above. constant references do not start with a $
Use the $GLOBALS array - $GLOBALS['site'] constants cannot be altered
Data Types constants are globally accessible
PHP supports four scalar data types
References to undefined constants are treated as string boolean - takes the values TRUE & FALSE literals. PHP defines five magic constants whose value integer - decimal, hexadecimal or octal. e.g. 32, 0x20, depends on where they are used
040. The constants PHP_INT_MAX and
Name
Description
PHP_INT_SIZE provide platform-dependent information. Integer overflow causes silent
__LINE__
Current line number transformation of the variable into a float.
__FILE__
Current file name with path float - Typically IEEE 64 bit with 14 decimal digits.
1

$lamp = array();
$lamp['L']='LINUX';$lamp['A']='Apache';
$lamp['M']='MySQL';$lamp['P']='PHP';
PHP arrays can be associations – i.e. a unique key, (e.g.
'L' above) is associated with each value in the array. For multiple dimensions use arrays within arrays.
Array Manipulation
Function
array_change
_key_case

Description
Guess!

array_chunk($ Returns an array of arrays containing arr,$size,[$f]) $size elements each from $arr.
TRUE for $f preserves keys. arra_fill_keys( $keys,$values)

Create an associative array using
$keys, and $values,.

array_fill($star t,$num,$value) Create an array with $num elements from index $start filled with $value

array_flip($arr
)

Flip values and keys in $arr

array_key_exi

Check for $key in $arr

PHP Quick Reference Card1.02 sts($key,$arr) [$options])

1:0

array_reverse( Reverses element order. $f = TRUE
$arr,[$f])
preserves keys.

Y

2008

y

08

array_values(
$arr)

Returns all values in $arr in a numerically indexed array.

count($arr)

Returns element count

a

am or pm

ksort($arr)

Sorts array using keys

A

AM or PM

g

1-12

G

0-23

h

01-12

H

00-23

i (Minutes)

OR PATHINFO_#
#
= uppercase keys above - into options for more selective results.

00-59

Time

1By default array indices start at 0. Here we force them to start at 1

Date & Time
Function
getDate([$time])

Description
Associative array with current time or $time exploded into
Key

Value

keys
'dirname',
'basename',
'extension' & 'filename'.

dirname($fname)

Counterpart of basename above

glob($pattern,
[$flags])

Returns array of all filenames matching $pattern. OR GLOB_# flags for more selectivity
# Flag

Purpose

0-59

s(Seconds)

0-59

U

0-23
1(!)-31

e

0(Sun)-6(Sat)

P

∆ to GMT

mon

1(!)-12

year

e.g 2008

yday

0(!)-365

Only folders
Stop on error

Europe/Paris

wday

Expand {a,b,c} and match

ONLYDIR

Timezone

mday

As is list

BRACE

UNIX Epoch

hours

NOSORT

00-59

minutes

Add slash

ERR

seconds

MARK

is_#($name)
# = dir or file

is $name a folder or a file?

chdir($dname)

Change current directory. FALSE on failure.

closedir($dhandle)

Closes directory opened earlier using opendir.

Linefeed, 0x0A

getcwd()

Get current directory

\r

Carriage Return, 0x0D

mkdir($dname,
[$mode,$recurse])

\t

Tab, 0x09

\v

Vertical tab, 0x0B

Makes directory $dname. $mode defaults to 0777 – ignored on
Windows. $recurse forces all directories in $dname to be created checkdate($month, Validates date for $year between
$day,$year)
1 & 32767

\f

Form feed, 0x0C

opendir($dname)

\\

Backslash

Opens $dname handle. date($format,
[$time])

\$

Dollar sign

readdir($dhandle)

Reads next filename from open directory. \”

Double quote
Char in hexadecimal

rewinddir($dhandl
e)

Guess!

\x00 - \xFF

rmdir($dname)

Attempts to delete $dname – subject to permissions. FALSE on failure

scandir($dname,
[$order])

Returns array of files in $dname.
Provide
$order
=
1 for descending name sort.

UNIX Epoch time

Escape Sequences

weekday

SundaySaturday

month

JanuaryDecember

0

UNIX Epoch

Formats current time or $time using $format.
Format Char

time()

Example

Day

Sequence
\n

File System

d

01-31

j

1-31

D

Mon

l(l.c. L)

Monday

N

1(Mon)

S

Suffixes st, nd etc. Use with j

w

0(Sun)

z

0-365

Function

file_exists($fname) Does $fname exist? Works with files & folders filesize($fname) Guess?

fileatime($fname)

When was the file accessed?
(UNIX time)

chmod($fname,
$mode)

Change access rights to file
$fname. $mode is an octal number in the format 0OGW where O = Owner, G = User group for Owner & W = the world,
i.e. everyone else. Individual digits are made up by adding the desired rights as listed below

Week of year

Month
F

January

m

Value

01-12

M

Description

basename($fname, Filename minus path – and
[$suffix])
extension if $suffix is provided

Week
W

Meaning

Jan

n t fclose($fhandle)

Close fopen'd file

fopen($fname,
$mode)1

Opens$fname. $mode can be
Mode

Meaning

r1

Read

r+1

Read/Write

w1,2,3

Write

w+1,2,3 Read/ Write

Year)?

Execute

a3,4

Write

Write

a+3,4

Read/Write

4

Days in month

(Leap

rename($old,$new) Guess!

2

1-12

Read

x1,3,5

Write

x+1,3,5

Read/Write

e.g. 0644 means read/write rights for owner & just read for others. pathinfo($fname, Returns associative array with

2

returns

disk_free_space($ Guess! dname) 1

Year
L

Right

and

1File pointer at BOF 2Truncate file to zero length 3Create file if required 4File pointer

PHP Quick Reference Card1.02

Specify an additional b (binary),
e.g. 'wb' for all write modes to prevent CR/LF character translation. Always specify b with all binary files, e.g. images. file_get_contents( $fname)1

Reads contents of $fname into a string. fread($fhandle,
$len)

Read to EOF or $len bytes from file opened for reading. fopen the file with 'b' in the mode flag.

fruncate($fhandle,
$size)

Truncates file open for writing.
Adds null bytes if $size > filesize.

fwrite($fhandle,
$str,[$len])

Writes $str to file opened for writing. Stops at $len if $str length is greater.

file_put_contents(
$fname,$data,
[$flags])

$num to e or $base

pi()

Approx value for π

pow($num,$base)

$num$base

rad2deg($rad)

Radians to degrees

rand([$min],$max)

Random value 0/$min.. $max.

$x = 0);
}
function forLoop($num){ for ($i=0;$i

Miscellanea
Warning – thoughtless use of the features described here could seriously damage your server installation.
The prepend operator, @, can be used with constants, variables, function calls, eval and include to suppress error messages.
The backticks operator `returns the results of running a shell command. For instance, `ls` - dir on Windows – would return a directory listing. This can be assigned to a variable or echoed to standard output. Typing 96 while holding down the ALT key is a keyboard layout independent way of entering the ` operator.

eval($expr) evaluates the PHP code provided in the break causes immediate termination of the loop. Loop string $expr. The string must be valid PHP code – statements after continue are skipped and the next inclusive of terminating semicolons. Errors in $expr may cause the parser to die. Code in $expr forms part of the execution of the loop is performed. parent script so variable assignments in $expr are function foreachLoopA(){ retained. foreach($GLOBALS as $key => $value){
PHP in HTML echo $key.'='.$value.'';
The safest way to embed PHP code in HTML is to
}
delimit it using the tag pair. Other syntax
}
exist but are not accepted by all web servers. The function foreachLoopB(){ resulting file should be saved with the extension .PHP. foreach($_SERVER as $value) echo $value.'';

4

You May Also Find These Documents Helpful

  • Satisfactory Essays

    cout << num1 << " + " << num2 << " = " << num1+num2;…

    • 426 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    The name can be of any length, but don't get carried away. Remember that you will have to type this name.…

    • 368 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    NISHAN KARKI

    • 1407 Words
    • 15 Pages

    Conc. Elective: Biol 315 (Sp only), 328 (Sp only), 329 (Sp only), 332 (Sp only), *421, 475…

    • 1407 Words
    • 15 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Week 3 Ilab

    • 367 Words
    • 2 Pages

    == = Set fso = CreateObject("Scripting. FileSystemObject") Set…

    • 367 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Vineet Nayar

    • 575 Words
    • 3 Pages

    Vineet Nayar is the vice chairman and CEO of HCL Technologies. HCLT is an India based global information technology service company. HCLT is one of the Indian IT leaders, recognized globally for its business performance and innovative and management practices.…

    • 575 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Nola Pender

    • 399 Words
    • 2 Pages

    And nurses have always been playing a big role in educating their patients on how to…

    • 399 Words
    • 2 Pages
    Good Essays
  • Better Essays

    Nayar of India

    • 2286 Words
    • 10 Pages

    Nayar is a Hindu caste of the India state of Kerala. The region contained small, feudal kingdoms, in each of which royal and noble lineages, the militia, and most land managers were drawn from the Nayars and related castes. Unlike most Hindus, Nayar traditionally were matrilineal. Their family unit, the members of which owned property jointly, included brothers and sisters, the latter is children, and their daughters’ children. The oldest man was legal head of the group. Rules of marriage and residence varied somewhat between kingdoms. This paper will include the examination of aspects of the life of the Nayar marriage, political organization, and belief and values.…

    • 2286 Words
    • 10 Pages
    Better Essays
  • Best Essays

    Haier

    • 3791 Words
    • 16 Pages

    Haier has become one of the top 50 transnational corporations in developing countries. In addition to refrigerators, Haier manufactures a wide range of household appliances including washers, dryers, freezers, microwaves, air conditioners,…

    • 3791 Words
    • 16 Pages
    Best Essays
  • Good Essays

    Nola Pender

    • 457 Words
    • 2 Pages

    Nola Pender’s desire to become a registered nurse began as a little girl when her aunt was hospitalized. “The experience of watching the nurses caring for my aunt in her illness created in me a fascination with the work of nursing” (Alligood & Tomey, 2010). Her experience developed into the Health Promotion Model (HPM) which is to be used as a guide to explore the biophysical processes that motivate people to engage in behaviors directed toward improving their overall health & well-being. Although this theory can be applied to all areas of nursing, using it in clinical practice to educate adolescents seems to me to be ideal. Adolescence is a unique time in ones life because although they are still “children”, they are also subjected to enormous outside influence which can be both positive and/or negative.…

    • 457 Words
    • 2 Pages
    Good Essays
  • Powerful Essays

    Haier

    • 1292 Words
    • 6 Pages

    Zhang Rui Min (Zhang) is the Chief Executive Officer (CEO) of Haier Group. Under his leadership, revenues at Haier had surpassed $12 billion with over 30,000 employees and he is recognized as one of the “50 most respected business leaders in the world.”…

    • 1292 Words
    • 6 Pages
    Powerful Essays
  • Good Essays

    Mr Haroon Iqbal

    • 2515 Words
    • 11 Pages

    The department processes FOI requests in Melbourne and Sydney. If you live in Victoria, Western Australia, South Australia, the Northern Territory or Tasmania, please send your request to: Freedom of Information Melbourne Department of Immigration and Citizenship GPO Box 241…

    • 2515 Words
    • 11 Pages
    Good Essays
  • Satisfactory Essays

    Anwar Chowdhury

    • 357 Words
    • 1 Page

    In Siegfried Sassoon’s World War I poem They a great amount of poetic devices such as irony and rhyme scheme are used to develop the overall theme of the poem. The poem holds a very dark and shocking side of a war within its meaning and theme. Drawn from Sassoon’s own experiences he had during his time in the First World War, The strong overall theme of the piece is the changes that war makes on someone.…

    • 357 Words
    • 1 Page
    Satisfactory Essays
  • Good Essays

    Haier

    • 545 Words
    • 3 Pages

    Haier, started as a defunct refrigerator factory in Qingdao, China, was China’s largest white-goods maker before its expansion to foreign countries and was named the leading refrigerator manufacturer worldwide after expansion. Generally speaking, it is successful both in China and abroad using its unique and leading managing concepts. Haier’s CEO knows well about the company he founded and is now looking for more achievements. For its further development, the CEO decided to focus on deeper market penetration. Which lessons from either China or abroad should be applied to each other in order to maintain Haier’s leading position is a concern for its managers.…

    • 545 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    A Report Of HAIER

    • 2538 Words
    • 11 Pages

    A SWOT & Value Chain Analysis of The Most Successful Chinese Emerging Multinational - Haier…

    • 2538 Words
    • 11 Pages
    Powerful Essays
  • Best Essays

    Haier

    • 3306 Words
    • 14 Pages

    In this report, it will introduce a famous Chinese electric appliances organization—Haier, which has involved into a giant multinational corporation, revealing that different environmental force, including economic, political, cultural and social and technological factors have had an impact on Haier’s operation and strategies. Besides, the report will also formulate some strategies that expect to enable Haier can adapt the changing competitive environment, sustain and grow the business constantly. Meanwhile, Haier should realize the internal unique strengths and weakness itself, seizing some helpful external opportunities and finding out the threats it should counter.…

    • 3306 Words
    • 14 Pages
    Best Essays