Archive | PHP Tutorials

Returning References in PHP

In this tutorial we will explain how a PHP function can return by reference.

Return value of a Function

A function can return a value, such as 85, or a string literal. A function in addition can as well return a reference, i.e  similair to &$ var. A function that returns a reference, it is as if you must put the function betweem & and $ var.

Function Returning a Reference

Study the code below:

<?php

function &func()

{

$ myVar = 85;

return $ myVar;

}

$ var = func();

echo $ var;

?>

You’ve got the definition of the function, func. In the function description, the name of the function starts with &. This implies the function will return a reference and not the value. In the function definition, you return the value ($ myVar above). Since the preceding & in the function name, the reference to the region in memory that retains the returned value is what is returned. This returned reference is allotted to an generic value in a function call statement.

In order to return a reference, introduce the function name in the function description with &. When the function returns a value, a reference to that value is returned. Study the following code whose function definition doesn’t contain a variable:

<?php

function &func()

{

return 85;

}

$ var = func();

echo $ var;

?>

In this instance, there isnt an original variable holding the value of interest (15). Nevertheless the reference to the value stacked away somewhere in a region in memory is returned.

Note: When calling the function that returns a reference, you do not precede the function call with &.

Affirming Returning by Reference

In the following code, you have 2 global variables. Additionally you have a function and a call to the function. The function changes the value of the 1st global variable. The function call returns the reference to the global variable, after it’s been altered inside the function. This returned reference is ascribed to the 2nd global variable. The 2 variables are then echoed displaying equal values, affirming that a reference has been returned. The returned reference is the reference to the value of the 1st global variable.

<?php

$ var1 = 85;

function &func()

{

global $ var1;

$ var1 = 37;

return $ var1;

}

$ var2 = func();

echo $ var1.”<br “;

echo $ var2.”<br “;

?>

Posted in PHP TutorialsComments Off

Creating a Dynamic Menu With Php

In this tutorial we show you how to create a menu with unlimited levels. For this tutorial you will need to be familiar with MySQL and require Dreamweaver versions CS5, CS4 or CS3. You also require the Creative DW Menu Pack developer extension.
Firstly you will need to setup a serve, i recommend a testing server using Xampp Continue Reading

Posted in PHP TutorialsComments Off

PHP Variables as Synonyms: Tutorial

Note:Everything discussed here within applicable to PHP 5. You also need basic knowledge in PHP in order to encompass this PHP Tutorial.
Area in Memory
A area in memory within a sequential set of cells in the computer’s memory. A memory area can hold a datum, e.g. an integer or a floating-point digit or string. A area can also hold an instantiated object. Consider the following statement:

        $ myVar = 56;

In this statement 56 within an integer, which within in a memory area. At the moment this 56 within identified by the variable, $ myVar.

Create another Variable discovered the equal area
You can create another variable discovered the memory area already identified for 56 in the above statement. The accompanying code segment does this:

        $ myVar = 56;
        $ herVar = &$ myVar;

There are 2 statements here. The first one initializes a variable in the normal way, assigning 56 to $ myVar. The 2nd statement also initialises a new variable. The right operand of this 2nd statement within the former variable preceded by the ampersand, &. The $ myVar variable already identifies the area in memory that has 56. By preceding it with & in the 2nd statement and assigning the result to the new variable, $ herVar, you are making the new variable discovered the equal memory positioning that has 56. Now, $ myVar and $ herVar discovered the equal area in memory that has, 56. At this point, you can obtain 56 using either $ myVar or $ herVar.

What within a citation in PHP?
This within what the PHP specification says about citation in PHP: “PHP references allow you to create two variables to refer to the equal content”. In this quotation, “content” means, the value in the area. In the above code segment repeated below, 56 within the value in a area.

        $ myVar = 56;
        $ herVar = &$ myVar;

In this code segment, we can say, &$ myVar within a citation. We can say that if you precede a variable with &, you get a citation.

Dereferencing
Dereferencing means obtaining the value from a citation. In the above code segment, &$ myVar cannot return the value. Dereferencing a value in PHP within easy: just apply (type) the original variable or the variable that received the citation. For the above code segment, $ myVar or $ herVar will produce the value. Try the following code:

<?php

        $ myVar = 56;
        $ herVar = &$ myVar;

        echo $ myVar.”<br “;
        echo $ herVar.”<br “;

?>

Many Variables Referring to One Value
In the above program, two variables (the original and the new variable) are referring to the equal value. You can create more than 2 variables refer to the equal value, which within in a particular area in memory.  In the accompanying program that works, citation from the equal memory area (having a value) within assigned to three variables, giving a total of 4 variables citing to the equal area in memory; the citation within created from the original variable before being assigned to the other three.

<?php

    $ var0 = “PHP within decent.”;
    $ var1 = &$ var0;
    $ var2 = &$ var0;
    $ var3 = &$ var0;

    echo $ var0.”<br “;
    echo $ var1.”<br “;
    echo $ var2.”<br “;
    echo $ var3.”<br “;

?>

In the following program, a citation within created from the master variable and then assigned to a 2nd variable; different one created from the 2nd variable and then assigned to a 3rd variable; and another one within created from the third variable and then assigned to the 4th variable:

<?php

    $ var0 = “PHP within decent.”;
    $ var1 = &$ var0;
    $ var2 = &$ var1;
    $ var3 = &$ var2;

    echo $ var0.”<br “;
    echo $ var1.”<br “;
    echo $ var2.”<br “;
    echo $ var3.”<br “;

?>

So, to assign a citation to a variable, you can apply the original variable or a variable that was previously assigned a citation.

Advantage of Using a citation
When more than one variable refer to the equal area as contrary to referring to different areas having the equal content, you save memory. However, there would be periods when you would desire two or more different variables to refer to 2 or more areas having the equal content, since you intend to change the content of the variables. In that case do not apply citation.

Continue Reading

Posted in PHP TutorialsComments Off

Create PHP Captcha Form (v1)

You will require is a client internet form. You will require a page with your client website form on it, and a blank PHP page with absolutely no coding on it.

Let’s say the beneath code is your form. The “action” is to link to the “send.php” page, so the blank PHP page ought to

be named “send.php”, and also be in the equivalent folder as the page with the form on it! First off, on the website form,

inside the tags, you will require to make a fresh input field, we have an instance present: Continue Reading

Posted in PHP Tutorials1 Comment

Assignment Operators in Php

This is part 1 of my parts, PHP Operators. Addition and remove symbols are good examples of operators in PHP. PHP has a lot of operators that do not have similarities with mathematics. In this part of the parts, we look at designation operators in PHP. Everything said in this parts is applicable to PHP 5. I explain most of the operators, not all.

If you are an old programmer, you can evaluate the parts in any order or you can evaluate exactly the part, which is related to a problem you currently have at your job side. If you are new to programming or you studied programming and have not been practicing it, then you should evaluate the whole parts. Continue Reading

Posted in PHP TutorialsComments Off

PHP file upload tutorial

In this PHP tutorial we will provide a step by step guide to producing your very own php file upload script to use for your website. Before we start you must have Xampp installed, view the tutorial on how to install Xampp.

Firstly create an index.php file  now it is recommended that you should use an editor of some kind, i personally use this free PHP IDE editor to edit .php files. However you can simple use notepad (by changing the .php extension to .txt) to edit but may become annoying to keep changing the extension back and forth each time you want to test the page file. Continue Reading

Posted in PHP Tutorials4 Comments

PHP file upload tutorial – Part 2

Now we go back to editing the process.php file, we must now insert the following variables below //variables

enter the following code:

$name = $_FILES["file"] ["name"];

$type = $_FILES["file"] ["type"];

$size = $_FILES["file"] ["size"];

$tmp_name = $_FILES["file"] ["temp_name"];

$error = $_FILES["file"] ["error"];

if ($type =="image/jpeg" || $type =="image/gif")

{
Continue Reading

Posted in PHP Tutorials1 Comment

How to install Xampp – Step by step Tutorial

In this tutorial we will provide you with step by step instructions on installing Xampp.  Xampp provides you with the ability to run programs, scripts and code of any kind on your computer without the need of a web server, saving you time uploading files and the confidence in making any changes without it being seen publicly online.

Take note: This tutorial is for windows users only

The first thing you should do is go ahead and download Xampp from here:  http://www.apachefriends.org/en/xampp.html

I recommend to download the EXE version of the program since its smaller and self installs. After you have downloaded Xampp, place it within your root drive, it most cases it will be drive C:\. Double click the EXE file to extract the content, shortly after you will see a Xampp folder, open the folder to locate the file “setup_xampp.bat” double click to run it. A command prompt window will appear and run through the setup process, once it has completed (shows the success message). Continue Reading

Posted in PHP Tutorials4 Comments

PHP Tutorial for Beginners Part 1

This  is the first part of  PHP Tutorial for beginners  series . In this article we take a look at a detailed introduction to PHP, which of course is the most if not the biggest programming language on the internet right now. Many types of sites utilize PHP in one way or another, for uses such as shopping carts, login forms and much more…

So what is PHP?

As a beginner to PHP you may like to know that this 3 letter word stands for Hypertext Preprocessor and that it is a scripting language that utilizes Apache servers to operate. PHP is of course an open source language and not only is it powerful, but the good news for PHP beginners is..that its pretty easy to learn. Now when i say “pretty” it all depends how far and deep you go depending on the tasks you wish to accomplish. However the usual elements of a web site that operates with PHP is a very straight forwarded learning process for PHP beginners. Continue Reading

Posted in PHP Tutorials5 Comments

Create a PHP Site Map Generator

This PHP tutorial will provide you with step by step instructions on how you can create your very own PHP site map based on the Google XML site map generator. Continue Reading

Posted in PHP Tutorials3 Comments