Snippets

Numbered Code Highlighter
This will hightlight the php code and number each line. This can be initiated in many different ways.

Tell A Friend Form
This is a simple tell a friend form that validates all of the necessary fields.

Users Online
Shows the amount of users online at a time.

Random Image Generator
This function will select a random image from a given directory.

Splitting A Record Into Pages
Copy this code to learn how to read in a text file and split it into pages.

Random String
This tutorial will show you to generate a compelelty random string.

OOP Form Validation
Just include this file when you want to validate a form. To make a require input, defined its name attribue like this: name="User||Required" and the variables inside of php will be $_POST['User'] or $User.

[PHP] Tags
Here is a function that let you use [PHP] tags in a string, like you would use in vB. It will higlight all the code within the tags. It also checks weather to add the opening and closing tags.

Image Counter
This code will generate a graphical image counter. All you have to do is replace 'path/to/image/' with the path to the directory where all the images are stored.

MySQL Class
Here is a class that will handle all mysql actions such as connect, query and such. I'm going to describe every single aspect of here, but you need to set the variables at the top to get a connection and then you can figure out how to actually use it.

Checking Variables
Here is the proper way to take action accoriding to weather a variable is set or not.

Add ... to a String
This code is a function that will automatically add ... to a string if it is too long. Copy paste the code into the file. Then if your string is called $string and you want to cut it off after 100 characters, and want to spit it out, use: echo strcon($string,100);

Rotating Banner
This is a snippet that will rotate a banner on a page. All you have to do is set $File and $Images to the paths to the images. It will just do the next image in $Images in order. It doesn't rotate banners for seperate users, it just goes through. Before you use it, create the $Stat file and set the contents of it to 0 and your ready to go!

Fix MySQL Errors
This is the most imporpant snippet code you'll ever learn when you want to use a db. It will tell you the error, if any with your last action with the db. Use it or you'll never catch problems in your scripts.

Display a mySQL Database
This code connects and displays everything in the database. Fill in the $host, $name, $password, $database, and $table wifh the name of the proper stuff. Then inside the {}, I gave a sample with the id, you can keep adding them for each column in mySQL.

Flat File User Online
This code simply displays the number of people currently visiting your site without the use of mySQL.

Recommended Books

PHP and MySQL for Dynamic Web Sites
PHP and MySQL for Dynamic Web Sites
by Larry Ullman
Review

Sponsors

Spoono Host
Spreadshirt

Featured Resources




Looking for web hosting? Use us! Reseller Web Hosting by Spoono Host. Want to Advertise? If you're lost, try the Site Map.
© 2000-2008 Spoono, LLC. All rights reserved. Please view our Privacy Policy and Terms of Service.