Category «Learn PHP programming, training and tutorials»

PHP

PHP array functions

List of functions that work with php arrays. array_shift() array_shift() – Shifts the first value of the array off and returns it, shortening the array by one element and moving everything down. All numerical array keys will be modified to start counting from zero while literal keys won’t be touched. array_pop() array_pop() – pop the …

PHP Display errors & Debug

To turn on error reporting 1. Set in php.ini 2. In php.code Check error logs on apache server Check errors in log file that is configured in etc/apache2/httpd.conf DEBUG Php useful debugging functions gettype($variable) – Get variable type; var_dump($variable) – Dumps information about a variable; get_defined_vars() – Return an array of all defined variables; debug_backtrace() …

Limiting upload file size in PHP

Limiting upload file size We can configure upload max file size in php.ini file, but this is a global maximum for all of PHP. If we want to configure max file size in a particular case, we can do that by adding an attribute to HTML form for MAX_FILE_SIZE. PHP will automatically detect that value …

PHP Arrays

An array is a collection of related values (a list of items) such as names of cities Creating an array $numbers = array(); //empty array To create an array use the function array() like: Numeric Arrays Numeric Arrays are arrays that use only numeric keys, called as numeric, indexed or ordered arrays. Associative Arrays Associative …

PHP Conditional Statements: if else, switch

If statement Execute the code if the condition is true If…else statement Switch statement Execute different code depending on a condition. The switch statement is similar to a series of IF statements If the value pass to the switch statement matches, the code that follows the case is executed. Example: Be careful! if we forget …

Difference between single-quoted and double-quoted

The most important difference between single and double quote, is that anything enclosed in single quotes is treated as literal text. Single quotes When using single quotes we must take care with apostrophes. To use the apostrophe in single quotes, we have to put backslash before apostrophe (which is named as escape character). The backslash …

How to create variables in PHP?

Creating PHP variables A variable is a container for storing data. In PHP, a variable must begin with the $ sign, followed by the name of the variable When creating variables in PHP, you need to follow some basic rules. Variable names can have any combination of letters, numbers and the underscore; A variable name …

Change PHP configuration without editing php.ini

This option can ve used if Your hosting company(especially shared hosting) doesn’t give you control of php.ini file. This list includes the php.ini directives you can set to configure your PHP setup. 1. Use .htaccess file This work only on Apache server! For example if we want to change default values php.ini values You must …

How to install PHP on Your own PC?

How to install PHP on Your own PC To run PHP on Your own PC You have to: a) install a web server install PHP install a database, such as MySQL or b) install XAMPP on Your PC XAMPP is a completely free, open source package, used to install easily Apache distribution on Your PC …