Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

PHP Examples, Part 2
PHP Examples, Part 2
PHP Examples, Part 2
Ebook160 pages1 hour

PHP Examples, Part 2

Rating: 1.5 out of 5 stars

1.5/5

()

Read preview

About this ebook

"PHP Examples" contains PART 1, PART 2, PART 3. This PART 2 describes PHP syntax: variables, arrays, functions, classes, objects, PHP files, intermixing with HTML and JavaScript. It is a PHP Programming Guide. Programming practice.

LanguageEnglish
PublisherAdam Majczak
Release dateJan 1, 2014
ISBN9781311866653
PHP Examples, Part 2

Read more from Adam Majczak

Related to PHP Examples, Part 2

Titles in the series (3)

View More

Related ebooks

Programming For You

View More

Related articles

Reviews for PHP Examples, Part 2

Rating: 1.3333333333333333 out of 5 stars
1.5/5

3 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    PHP Examples, Part 2 - Adam Majczak

    PHP Examples

    PART 2

    by Adam Majczak

    The Smashwords Edition, 2014

    English e-Edition, License Notes

    This e-book is licensed for your personal use only. This e-book may not be re-sold or given away to others. If you would like to share this book with another person, please purchase an additional copy for each recipient.

    While every precaution has been taken in the preparation of this book, the publisher and the autor assume no responsibility for errors or omissions, or for damages resulting from the use of the

    information contained herein.

    ENGLISH EDITION, PART 2: PHP Programming

    CONTENTS:

    PART 1: Introduction to PHP

    PART 2: PHP Programming

    PART 3: Advanced PHP

    PART 4: Appendix, more examples

    PART 1: Introduction to PHP

    CHAPTER 1: Introduction to the e-book edition

    Similarities and differences: PHP vs. C/C++

    What and how can PHP do for us?

    What for? To get visitor’s IP, for example

    What do I need for beginning?

    CHAPTER 2: How to use PHP?

    Embedding PHP

    Comments in PHP

    How to use PHP interpreter online

    Running PHP from the command line

    Command line input (STDIN)

    CHAPTER 3: PHP variables

    Case sensitivity

    Error messages and warnings

    Data types in PHP

    Using constants in PHP

    Integer data type

    Floating-point numbers

    Bool type (Boolean values)

    Null type variable and type checking in PHP

    Dynamic variables

    CHAPTER 4: Operators

    Arithmetic operators

    Assignment operator and combined operators

    Pre / post - increment and decrement operators

    Comparison operators

    Logical operators

    Base converting functions and bitwise operators

    Operator precedence

    Filtering mask with binary operators

    CHAPTER 5: PHP Arrays, array constructor, array types in PHP

    Numeric indexed arrays, runtime array size change

    Associative arrays and string arrays

    Character strings as 1D array

    Mixed arrays

    Multi-dimensional arrays, hash table

    Array elements can be sorted

    Internal pointer and some useful functions

    CHAPTER 6: If we need conditional statements or loops

    If statement (if-elseif-else) and switch-case statement

    The while and do-while loops

    The for and foreach loops

    The break, continue and goto keywords

    PART 2: PHP Programming

    CHAPTER 7: Custom functions

    Argument passing by value and using default values

    Variable argument list

    Argument passing by reference

    Returning an array or modifying values by reference

    Locals vs. globals

    Math functions

    Searching and sorting

    Quick binary search

    PHP runtime-created functions

    Date and time

    CHAPTER 8: Object oriented programming in PHP - classes

    Properties

    Creating an object (a class new instance)

    Constructor

    Destructor

    Included and required file(s)

    CHAPTER 9: Programming practice

    Static methods

    Declaring constants within classes

    Magic constants

    Static properties in use

    Recommended OOP practice and The Gold Rule

    CHAPTER 10: Object-oriented programming

    Inheritance – first glance

    Overriding class members

    Final keyword and instanceof operator

    Access levels before and after inheritance

    Generating HTML page using PHP functions

    Generating the same HTML page using classes and methods

    A few words about PHP scope

    Interfaces, abstract classes and traits

    Abstract data types (ADT) and the abstract keyword

    Traits

    CHAPTER 11: Data input in PHP

    How HTML forms work

    Variables and superglobal PHP arrays

    Processing forms in PHP

    Simple form example and a little more about form processing

    Intermixing HTML and PHP

    Using PHP interpreter online and JavaScript codes

    PHP intermixing with JavaScript, how it works

    Information Feedback: Client-Server-Client-Server dialogue

    The precise Real Time Clock in PHP

    CHAPTER 12: PHP interaction with operating system and file system

    PHP interaction with operating systems being system-dependent

    Basic file-related functions

    More about opening a file by fopen() function

    SPLFileObject, SPLFileInfo objects

    Directory – related functions

    STDIN and STDOUT streams and piping

    A simple way to place an image in PHP

    How to create graphs and function plots in PHP

    PART 3: Advanced PHP

    CHAPTER 13: Effective programming in PHP

    Variable scope in PHP vs JavaScript

    Algorithm complexity and recursive functions

    Fibonacci sequence and factorials

    Programming errors

    Type setting and casting to avoid some errors

    CHAPTER 14: Using local storage in JavaScript and with PHP

    Counting views in JavaScript on the client side

    Single file PHP calculator

    PHP Cookies

    Creating Cookies in PHP

    $_COOKIE[] array and $HTTP_COOKIE_VARS[] array

    Deleting cookies

    Checking a cookie value in JavaScript

    Sessions

    CHAPTER 15: Advanced object oriented programming

    Using __set() and __get() methods

    Property and function overloading

    More about lambda functions and closures

    Namespaces

    Namespace aliases

    CHAPTER 16: Data validation and error handling

    Listing form variables

    Error handling

    Switching form On/Off using a single flag (the simplest validation)

    Data validation on the client side (JavaScript)

    Validation on the server side using PHP

    The NaN and Infinity errors

    Exception handling

    CHAPTER 17: XML, TCP/IP and Real Time data processing

    SimpleXML in PHP

    XML processing in PHP

    The DOM and SimpleXML examples

    TCP/IP

    How to evaluate real speed of our Client-Server feedback loop

    Function call time measuring

    Random numbers and a simple PHP game

    PART 4: Appendix, more examples

    CHAPTER 18: Simple examples

    Shared operating memory in PHP

    Login and password – why data encryption is needed

    A few words about data encryption in PHP

    APPENDIX

    Polymorphism example

    Converting relative path to absolute path

    How to get visitor’s IP?

    File uploading from user’s disk

    Setting timeout on the client side and on the server side

    Regular expressions – what it is and what for?

    Creating and showing an image gallery

    Drawing boxes by intermixing PHP, HTML and CSS

    Drawing y=cos(x) graph in PHP

    Unicode in PHP

    Simple geo-location based on IP

    Some useful links

    An ERROR in PHP5 discovered

    BC Math functions vs. PHP operators

    Pointer to an external process

    PART 2: PHP Programming

    This is the QUICK REFERENCE TO PHP for students, IT engineers and for all newcomers. Besides of numerous PHP examples this e-book contains also some simple JavaScript code snippets to show how to perform data processing on the client side by JavaScript and on the server side by PHP. Those are always the two alternative methods to select by programmers. So I have compared hereby some popular programming techniques being frequently used and providing complementary solutions. Because this e-book and these examples was written by and for programmers, PHP comes here with an extensive set of features and functions.

    The most interesting codes - see:

    * Information Feedback: Client-Server-Client-Server dialogue (CH 11, CH 17)

    * Effective programming in PHP (CH 11)

    * A simple way to place an image in PHP (CH 12)

    * How to get visitor IP (APP A)

    * Algorithm complexity (CH 13)

    CHAPTER 7: Custom functions

    PHP comes with a large number of built-in functions such as string and array handling functions. Other functions depend on what extensions PHP is compiled

    Enjoying the preview?
    Page 1 of 1