Detailed Guide On Arrays In PHP

Good Day!

Here is yet another article of Fast PHP Articles Series. Today we are going to discuss ARRAYS. We will learn its syntax, its different types, the different built-in Array functions that help to perform different tasks related to Arrays quickly and different practical examples explaining the use of Arrays in PHP.

By the end of this article you should be able to ,

- Define Arrays :)
- Use different types of Arrays
- Use different Built-in functions related to Arrays e.g list(), each(), var_dump, print_r, var_export()

- Write basic as well as complex php code using Arrays.
- Working with multidimensional arrays
- Understanding Foreach loop with the help of different examples

Read the rest of this entry »

Loops in PHP

Related Articles:

FAST PHP Tutorial (Part 1)
How to Install PHP on Windows (Fast PHP Tutorial Part 2)
How To Install PHP On Linux
How To Install Apache on Windows
Easy Installers to Install PHP, MySQL, Apache on Windows
PHP Programming Basics
Operators in PHP
Decision Making using IF-ELSE in php
Decision Making using PHP Switch Statement

Hi guys,

I have been receiving very good feedback from different users from different countries and I am loving it :)

I have replied to all of those students who have sent me their assignments and have asked any questions though I will request you to ask questions in the comments of a specific articles so that other readers can also get knowledge about the points you ask me.

Let’s move towards our today’s lecture which is about Loops.

There are certain conditions in which you need to execute the same block of code again and again. For example if you want to print ten consective equal signs in three lines to make a separater then you could do it with different methods. One could be to use three echo statements and put ten equal signs in each i.e

Quick Code


<?php
  echo "==========" . "<br>";
   echo "==========" . "<br>";
echo "==========" . "<br>";
?>

Read the rest of this entry »

Decision Making using PHP Switch Statement

Hi,

Here is a good shepherd with his sheep again :)

Today I am going to discuss Switch Statement. The basic concept of Switch is similar to the IF-ELSE statement; it helps you to write decision making code just like IF-ELSE but it is a little more organized, elegant and handy when dealing with complex logics as compare to IF-ELSE.

Remember, you can convert every IF-ELSE programme to Switch syntax but vice versa is not possible in some situations.

Remember one more thing, it is not necessary to convert IF-ELSE to Switch and vice versa, just use whatever suits to your needs, though when handling the complex and large decision making code I would suggest to use Switch.

Let’s have a look at its syntax.

Switch Statement Syntax:

Read the rest of this entry »

Decision Making using IF-ELSE in php

Dear students,

today we are going to study the tools that will help you to write Decision Making Codes in php. For example, when you sign in to orkut.com you see a message ‘hello username’ on the upper right of every page. Similarly when you login to gmail if you provide wrong username or password you see an error message and if you submit accurate information you are taken to the inbox.

If you think deep on these events, this is what we call ‘decision making code’. your write intelligent code that can make decision on user’s input and can act accordingly to the input to produce required output.

Read the rest of this entry »

Operators in PHP

Dear pupils,

I hope you would have been practising the last lecture ( PHP Programming Basics ) as I am getting feedback from different students from different countries and I am very happy I am able to contribute to PHP through my series of PHP Articles for beginners and professionals.

Today we are going to discuss different types of operators used in PHP. I hope you remember the basic definition of the operators and operands from my last article ( PHP Programming Basics ) and I am not going to explain it again as we had promised in the very first article of this Series of PHP Tutorials that we will not see behind and this is just to compell you to concentrate on each and every article of this series and practise (O! I love practice)

Read the rest of this entry »

PHP programming basics

Hi,

In previous articles we have covered topics like

How to install PHP on windows
How to install PHP on Linux
How to install Apache on Windows
PHP, MySQL, Apache installers

By now, I hope you would have set up your system to start actual PHP programming.

Lets start PHP programming.

Read the rest of this entry »

Easy Installers to Install PHP, MySQL, Apache on Windows

Hi

You have learned How to install PHP and Apache on Windows and Linux manually in my previous articles. Today I am going to tell you about ready made installers that make your lives easy to install PHP, MySQL and Apache on Windows by a single setup file.

WAMP: Installs PHP , MySQL and Apache etc on Windows

WAMP5 will allow you to discover all the PHP5 new features :

Objet support, SQLite built-in, SimpleXML, exceptions…

WAMP5 is build with standard conf files and most of the extensions. WAMP5 add-ons wil add new features to your server like PHP4, Perl, Zend Optimizer…

For further information please visit their official website at http://www.wampserver.com/en/

the other well-known is

XWAMP: Installs PHP , MySQL and Apache etc on Windows

XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. XAMPP is really very easy to install and to use - just download, extract and start.

for further information please visit their website at http://www.apachefriends.org/en/xampp.html

Another good installer called PHPtriad can be found at http://sourceforge.net/projects/phptriad

However, this is a dead open source project (at the time of writing this article) and is no more supported by the vendor so it contains old versions of Apache, PHP and MySQL.

I hope by now it will be piece of cake for you to setup your PC to run PHP MySQL and Apache with Windows and Linux. Do it as soon as possible because in the coming articles we will start learning PHP.

How To Install Apache on Windows

Good Day!

We are proceeding well as I am getting your feedback on the previous articles of Fast PHP Tutorial Series and I am happy to hear that they are working and you are learning something…

Till now we have learned “How to Install PHP On Windows” and “How to install PHP on Linux”. Lets start our today’s article which is about installing Apache on Windows so that it can support your PHP scripts on your PC.

First of all download apache,Win32 Binary (MSI Installer), from http://httpd.apache.org/download.cgi

You can choose the mirror according to your location to get fast downloading speed.

when you will run the downloaded installation file make sure to put right settings info may be as follow,

Network Domain: localhost

Server Name: localhost

Admin Email: youremail@domain.com

You may get Anti-Virus or Windows XP SP2 security alert about running apache as service. Allow apache to run as service on your windows.

You must run apache to execute PHP scripts and you can stop it optionally when you are not working with PHP and don’t need apache to waste your system resources.

After apache installation you will be able to see Apache Status Icon in your System Tray; sorry… what did you say? what is system tray? … well, the area where your system displays click (time) or display msn, yahoo and icq etc icons is called system tray.

Apache shows a green kinda icon if it is running and red icon if stopped. you can take mouse on the icon to see the status on mouse-tip. You can also start and stop apache from Start Menu as Apache have made a menu from where you can also run Test Configuration to check your apache installation. If you click on Test Configuration and a dos window appears and then disappears it means installation is working otherwise it will display informative error.

Now to test your Apache Installation on Windows open a browser window and type

http://127.0.0.1/ or http://localhost/ in the address bar. If it shows you Apache home page it means your apache is working.

Now you have to tell Apache where to pick your website pages, for this open the http.conf (apache configuration file) with notepad and search for DocumentRoot and put your website files exact location which may be,

DocumentRoot “C:/PHP_code/htdocs”

now search for and paste your DocumentRoot path here too
Remember whenever you make changes to Apache configuration file you need to restart apache to make the changes take effects. So, what are you waiting for… restart and get ready to dive deep into the PHP-Sea as your system is ready by now to start learning PHP.

How To Install PHP On Linux

Dear Students,

Today we will learn how can we install PHP on Linux. Lets go through these steps,

You must be logged in with the admin account to install PHP so login as root

We need to get installation files from the PHP Website and save it on your hard drive. You can download it to your download directory where you download all the files from internet or if you have not made one yet then lets create a download directory

mkdir /usr/local/download

Now we will download installation file from php ftp website to our download directory

    cd /usr/local/download
    ftp ftp.php.net
    cd pub/distributions
    bin
    get php-5.2.0.tar.gz
    bye

the file name may differ according to the PHP version you are downloading. I have downloaded the latest stable release of PHP i.e PHP 5.2.0

Now we are ready to install PHP. Lets go to the download directory

cd /usr/local/download

Now use this tar command

 tar xzf php-5.2.0.tar.gz -C ../etc

this command will install PHP from download directory to /usr/loca/etc/

Did you see the name of installation folder in /etc/ directory? …arrrgh! isn’t it ugly? lets rename it to something good,

 cd /usr/local/etc
 ln -s php-5.2.0 php

now it is acceptable … the next step is to compile PHP with this command

 ./configure –with-apache=../httpd –with-config-file-path=/www/conf –enable-track-vars
now make a PHP executable with

make

which will take some time and then install it with

make install

do you think we are done? well, unfortunately no… we need to add php module to apache with this,

cd ../httpd
./config.status –activate-module=src/modules/php5/libphp5.a

 

then

make

then stop apache and install new binaries,

bin/apachectl stop
make install

restart apache now

bin/apachectl start

if you have read my article - How to install php on windows then you must know by now that we have to change move the php.ini file to the proper location

cd ../php
cp php5.ini-dist /www/conf/php5ini

and remove-dist from its name.

Do you think we are done with PHP installation on Linux? well, fortunately yes.. we are … now you can make a test page with

< ?php echo "PHP ! I'm gonna get you.."; ?>

and browse this page if you see what you wrote your php is working fine otherwise it has some problem, test all the steps again and if still stuck with it ask for help here :)

How to Install PHP on Windows (Fast PHP Tutorial Part 2)

Hi dear pupils!

Today we will learn,

  1. How to Install PHP on Windows
  2. How to Install PHP on Linux
  3. How to Install Apache on Windows to support PHP
  4. How to run PHP with IIS

lets begin with How to Install PHP On Windows

Well, first of all visit PHP Official Website and download Windows Binary Installation files. There are different versions of PHP the latest version is PHP 5.2.0 at the time of writing this article.

One more thing, you will see two kinds of Windows Binary files .zip and .exe I am going to follow .zip file installation as .exe will not install PHP as Apache module on Windows. So if you are going to follow this tutorial then download .zip file.

Now create a directory for your PHP installation typically on “C:\PHP”, and create a temporary directory, may be “C:\PHP\temp” to unzip the files. As we don’t need all the files included in the .zip archive for PHP installation so first we are going to unzip the files in the temporary directory that we just created and then we will copy only those files to main “C:\PHP” directory which are needed for PHP installation.

Now unzip the downloaded file to the temporary directory “C:\PHP\temp” and copy the following files to main PHP directory “C:\PHP”

  • php.exe
  • php5ts.dll
  • php5apache.dll
  • php5apache2.dll

the file names will differ according to the version of PHP you downloaded. Remember we need php5apcahe.dll if you want to run PHP with Apache 1.3 version and php5apache2.dll for Apache 2.x version so you can skip one of them. You can find these files in the temporary directory (where you unzipped the zip archive) under ’sapi’ folder.
Also if you want to use the different PHP extensions then copy files in extensions folder from temporary directory to main PHP directory though make sure your PHP is working fine before messing up with extensions’ installation.

Also MySQL is already enabled by now and you don’t need to do anything extra to enable it with PHP.

Now copy the php.ini-dist file to your Windows installation folder typically C:\WINDOWS and rename it to php.ini (remove -dist from the name)

Congratulations! you are done with the PHP installation on Windows :)

However, let me tell you some additional information about configuring PHP to fit to your needs and requirements.

PHP Configuration:

If you want to use posted variables with their direct names e.g $var1, $name etc then you need to switch on the Global Variables in the php.ini file that we just moved to Windows installation folder. Open the php.ini file with notepad and search for this line

register_globals = Off

change Off to On and you are done.

Remember if you will not turn it on then you would have to access your posted variables with the REQUEST GLOBAL ARRAY reference i.e $_REQUEST[’var1′] etc

Setting Up SMTP SERVER:

If you want to send emails from your local PC using your ISP then you need to set up your SMTP server in the php.ini file , search for this code
[mail function]

;for win32 only

SMTP = localhost

;for wind32 only

sendmail_from= me@localhost.com

and change it accordingly to your SMTP server settings e.g

[mail function]

;for win32 only

SMTP = mail.yourisp.com

;for wind32 only

sendmail_from= you@somemailservice.com

If you are terribly confused with this SMTP thing then don’t worry, You are a NEWBIE ! so just forget about it and once we are handling Mail in PHP then you will understand the need and use of SMTP server etc

« Previous entries ·