Archive for the 'PHP Tutorials' Category

Output Data from Text File with PHP

Written by admin on Wednesday, May 7th, 2008 in PHP Tutorials, General.

In this tutorial I am going to teach you how to generate data from a text file with the use of PHP.

To start you must first make a document called data.txt

Open up your data.txt for editing (I highly recommend using Notepad++).

Now put the following code into your text file.


| News 1 | News 2 | News 3

The above is what we can output. Each phrase is separated by a |. We need this so that we can tell our php script when to stop outputting a piece of data.

Now you need to make a PHP file called quotes.php.

This is the file that will generate our data.
Insert the following code into your php file.

(more…)

PHP Connection to a database

Written by admin on Tuesday, December 25th, 2007 in PHP Tutorials.

PHP and MySQL there has to be a connection somewhere to use them both. But how do you make a connection?

Below will show you.

First…

You should never store any of your connection information anywhere other than in a PHP
document.

Now lets get started.

Create a php file called config.php and place it in the same directory as your index page.

(more…)

PHP Arrays

Written by admin on Tuesday, December 25th, 2007 in PHP Tutorials, Tutorials.

PHP is able to store data in a wide variety of ways. One way is arrays. The power to
store data seperately and output it multiple times easily.

Arrays carry data seperately once you have defined it. So if you had the data “one” and
“two” you could hanlde these 2 peices of data seperately from one variable. Here is an example of how it is stored:

<?php
$myarray 
= array(‘one’,‘two’);
?>

Also double quote or single quote can be used unless using complex arrays.
These 2 peices of information are now stored in one array but in 2 peices. To get this
information you do the following:

(more…)

PHP Includes

Written by admin on Saturday, July 7th, 2007 in PHP Tutorials.

PHP has a very handy function called include(). This includes a page within the current page seamlessly. Whereas using iframes or frames in HTML is a seperate page to the parent one. include() can be very useful for when you want to inclide content based on a certain topic. Many CMS programs use the function and so do many many scripts. Here is an example of how include() is used:

<?php

include(‘file.php’);

?> The above code will put all the contents of file.php inside the current parent page. It will inherit all of the variables currently being used by the parent page aswell. So if there are database connections file.php will be able to use them without having to connect again.

(more…)

PHP Sessions

Written by admin on Wednesday, June 20th, 2007 in PHP Tutorials.

Well, today we are going to be learning about PHP Sessions. So lets get started.
A session is well, a session. It is a time period for a visit in PHP’s terms. It can keep all visitor information or any other information in it while navigating to different pages. But you cant just start using sessions in your page whenever you want. There is some header information we need to take care of.
So let’s get learning the session headers.

Sessions must be started before you can use them. So to start a new session we use the following code:

session_start(“session_name”);

The function speaks for itself. Start a session. the words in quotes is the name of the session. We need a name because if another website is open at the same time, we dont want the session conflicting with each other. So now we have that sorted we can get onto using sessions.

(more…)



Site Navigation