Skip to content

Instantly share code, notes, and snippets.

@houssemz
houssemz / date.md
Created November 6, 2018 15:56
date and time

Datetime

These functions allow you to get the date and time from the server where your PHP scripts are running. You can use these functions to format the date and time in many different ways. The date and time information is stored in 64 bit number so negative years are supported.

date. * functions are affected by PHP.INI settings.

@houssemz
houssemz / json.md
Last active August 20, 2018 15:53
Json, AJAX and PHP

JSON and PHP

  • Json is an acronym for JavaScript Object Notation
  • DATA-interchange format
  • 🔥 extension load in PHP by default

PREDEFINED CONSTANTS (examples)

  • JSON_ERROR_NONE confirms whether error occurred or not
  • JSON_ERROR_SYNTAX indicates syntax error
  • JSON_ERROR_UTF8 encoding issues
@houssemz
houssemz / soap.md
Last active August 18, 2018 13:30
SAOP

SAOP and PHP

SAOP is an acronym for Simple Object Access Protocol. It is an XML-based messaging protocol for exchanging information. SAOP is an application of the XML specification.

Points to note :

  • SOAP is a communication protocol designed to communicate via internet.
  • SAOP provides data transport for Web Services.
  • SOAP is a platform and language-independent.
  • SOAP is the XML way of defining what information is sent and how.
@houssemz
houssemz / DOM.md
Last active July 1, 2018 13:21
The Document Object Model extension allows to operate on XML documents through the DOM API

The XML DOM Parser :

The DOM parser is a tree-based parser.

Load and Output XML :

Exp :

<!-- file.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<note>
    <to>Tove</to>
@houssemz
houssemz / XML.md
Last active June 28, 2018 13:25
PHP extension lets you create XML parsers and then define handlers for different XML events

Installation :

  • This extensio is enabled by default. It may be disabled by using the following option at compile time : --disable-xml if you comiple PHP ad a module for Apache
  • This extension has no configuration directives defined in php.ini

XML Parser functions :

xml_parser_create -> create an XML parser. xml_parser_create_ns -> create an XML parser with namespace support.

Character encoding :

@houssemz
houssemz / Tips.md
Last active June 28, 2018 10:48
Tips that can come as question in PHP certification

🚫 Functions names are case-insensitive !

<?php

define('CONSTANT', 1);
define('_CONSTANT', 0);
define('EMPTY', '');

if (!empty(EMPTY)) {

Error handling

Predefined constants :

Default errors :

Value Constant Description
1 E_ERROR Fatal run-time errors. Execution of the script is halt.
2 E_WARNING Run-time warnings. Execution of the the script is not halted.
4 E_PARSE Compile-time errors. Should only be generated by the parser.

GLOBALS :

An associative array containg references to all variables defined in the global scope of the script. The variable names are the keys of the array

$_SERVER :

Is an array that containing inforamtion such as headers, paths and script locations.

Prior to PHP 5.4.0, $HTTP_SERVER_VARS contained the same initial information, but was not a superglobal. (Note that $HTTP_SERVER_VARS and $_SERVER were different variables and that PHP handled them as such.)

⛔ You may or may not find any of the following elements in $_SERVER if running PHP on the command line.

Post increment vs pre increment

<?php
$i = 10;
$a = $i++;
// Now $a is 10, and $i is 11

$i = 10;
$a = ++$i;
@houssemz
houssemz / namespaces.md
Last active June 28, 2018 09:52
Namespaces

Defining namespace :

Any valid PHP code can be contained within a namespace. But only the folowing types of code are affected by namespaces :

  • classes (including traits and abstracts)
  • functions
  • constantes

A file containg a namespace keyword must declare the namespace at the top of file and before any code. The only code allowed before namespace declaration is the declare statement for defining the encoding.