CancelImage Upload

Topics: PHP
Read our latest entries.
Posted by Garren Harland on September 23, 2009, 1:49 pm.
Throughout your PHP programming career you will no doubt at some point (or rather at many frequent points) require a function to return the size of a given array. Here then is a code example making use of just such a function.
Click here to read on.
Posted by Garren Harland on September 16, 2009, 9:43 am.
If you are performing a preg_replace on a string it might well be that you do not mean to replace every match within it. Instead you might only want to replace the first item, or a specific number of items.
Click here to read on.
Posted by Garren Harland on September 11, 2009, 11:36 am.
Let's face it: only the biggest Photo enthusiasts on the planet will want to spend endless amounts of time resizing hundreds of images one at a time. Your average individual or web designer neither has the will or the passion for that kind of display of commitment.
Click here to read on.
Posted by Garren Harland on September 7, 2009, 11:41 am.
If you are writing a PHP application that is dealing with data related to weather conditions you will no doubt at some point have to convert between Celsius and Fahrenheit. To perform these conversions two simple formulas are required.
Click here to read on.
Posted by Garren Harland on September 7, 2009, 10:52 am.
England has never been a country willing to fit in. Never has there been any interest in driving on the right hand side of the road, and when asked how many kilograms are found within a Stone, the reply will often be along the lines of.
Click here to read on.
Posted by Garren Harland on September 5, 2009, 10:39 pm.
If you want to give your users a specific code you will need to make sure that it really is random and unique. To accomplish this task PHP has a suitable function to offer, as it usually does.
Click here to read on.
Posted by Garren Harland on September 5, 2009, 3:39 pm.
The easiest way to load all the image source attributes from any given HTML document with PHP is by using the DOM library. If you have not encountered DOM functions before you are in for a treat. They make accessing individual components within a HTML document very simple, often providing easy solutions where previously you might have had to string together regular expressions.
Click here to read on.
Posted by Garren Harland on September 5, 2009, 3:10 pm.
Loading all the links from a specified website automatically may sound like a huge task? Well, thanks to PHP's DOM library it is a piece of cake. Here is a step by step guide to loading all the link tags contained within a specified page.
Click here to read on.
Posted by Garren Harland on September 5, 2009, 1:14 pm.
The following page will discuss how to load an image's size details into an array. These details can come in handy with functions to create thumbnail versions of an image, or simply to specify an image's exact dimensions inside an image tag.
Click here to read on.
Posted by Garren Harland on September 5, 2009, 11:58 am.
If you own an interactive website where your users can upload their files, you will need to insure that each file has a unique name that can be used as an identifier. One way to accomplish this task is to add a timestamp to the filename. Granted two users could upload a file with exactly the same name at exactly the same time. But unless you have a website with billions of visitors per day you should be safe.
Click here to read on.
Posted by Garren Harland on September 5, 2009, 11:16 am.
While deleting a folder is no more difficult than deleting a file (though requiring a different set of functions), there are a few things that need to be taken into account. For starters that the file will not be removable till you have deleted each of it's files one by one. To accomplish this you will need to use a combination of the function readdir() to load all the filenames within a folder, and then one by one deleting them with the file delete function that I have previously discussed.
Click here to read on.
Posted by Garren Harland on September 5, 2009, 10:43 am.
While deleting a file in PHP only requires one simple function, you will want to contain it in a pack of if statements that indeed check for whether or not the file first of all exists, and if it does you will want to know if it has indeed been deleted.
Click here to read on.
Posted by Garren Harland on August 31, 2009, 11:36 am.
The following tutorial discusses how the metric unit meters can be converted into yards and feet with the help of PHP. Naturally enough these same conversion numbers can be used to perform the conversion in other programming languages.
Click here to read on.
Posted by Garren Harland on August 31, 2009, 10:37 am.
This tutorial will discuss how Kilograms (KG) can be converted into stones or Pounds with PHP. Especially the stones are easy to calculate from KG, once the number of pounds has been established. For the sake of accuracy this in-between step can be seen as a necessary one.
Click here to read on.
Posted by Garren Harland on August 30, 2009, 6:33 pm.
If you are looking to send both a HTML and Plain Text version of an email in PHP, you will require a more advanced format of the PHP mail() function. To make this work first of all a HTML and Plain Text alternative have to be written.
Click here to read on.
Posted by Garren Harland on August 30, 2009, 5:30 pm.
Although this should usually not happen to an organised programmer, there may come a time with 30'000 plus lines of code, that a track is lost on a certain variable, and that a function is required to check what type of variable once was defined.
Click here to read on.
Posted by Garren Harland on August 30, 2009, 4:59 pm.
Cookies are a useful tool for returning visitors. For instance login details and other items can be stored, and old session states from the last visits can be stored based on these.
Click here to read on.
Posted by Garren Harland on August 30, 2009, 4:17 pm.
A lot of programmers struggle to understand the principle behind headers, and how they are supposed to be defined right at the start of a pages code. It is no good defining them halfway down the page.
Click here to read on.
Posted by Garren Harland on August 30, 2009, 3:51 pm.
When you have thousands and thousands of lines of code it is sometimes hard to tell if a variable has already been set. Of course most programmers will simply check if the string is equal to NULL, but this may not be sufficient all the time. A string can after all have been set, and then later on been given the value of NULL.
Click here to read on.
Posted by Garren Harland on August 30, 2009, 2:14 pm.
As you are no doubt aware speech or quotation marks in the wrong place can cause havoc within a PHP code. The following example for instance will without a doubt produce an error.
Click here to read on.
Posted by Garren Harland on August 30, 2009, 1:27 pm.
To choose between different Content-Types for Russian Cyrillic symbols in PHP we can use the function convert_cyr_string(). This function enables us to switch between the following character sets.
Click here to read on.
Posted by Garren Harland on August 30, 2009, 1:08 pm.
To count the number of appearances of each character within a string we can use the following PHP function.
Click here to read on.
Posted by Garren Harland on August 28, 2009, 7:09 pm.
Encoding data to be sent via AJAX can turn into a nightmare in some languages. Usually encoding the data with the JavaScript function encodeURIComponent() and decoding it with a function such as PHP's rawurldecode() will prove enough to send and receive data the other end via AJAX. However, this is not always the case. Recently I had a Russian client who needed a guestbook. And although the AJAX worked fine in sending Latin characters, and even managed to post German and French letters such as ä, ë, ö and ö, the Russian characters were misinterpreted.
Click here to read on.
Posted by Garren Harland on August 28, 2009, 2:50 pm.
The ability to resize images, and through doing so generating thumbnails, is of great importance to any interactive website where the users can themselves upload images. This is mainly because you average user is completely unaware of how big the image is that they are uploading. It could be 200 x 150 pixels, or 2500 x 1600, to most the dimensions would not mean much.
Click here to read on.
Posted by Garren Harland on August 22, 2009, 12:38 pm.
Sending special characters such as plus symbols through an AJAX form to be received the other end requires a bit of trickery. Often when programmers experience trouble with this kind of transmissions there was either...
Click here to read on.
Posted by Garren Harland on August 19, 2009, 8:19 pm.
If you are building a site indexing website that needs to scan a page's title and meta tags the PHP function get_meta_tags() is the thing that dreams are made out of. Sure, you could write a bunch of regular expressions to extract meta tags and all their information from a website. But then again you could save yourself the time and practice your gloating face instead!
Click here to read on.
Posted by Garren Harland on August 19, 2009, 4:23 pm.
To transfer all elements of an array into one string the function implode() is required. Simple specify the array that is to be imploded along with a separator.
Click here to read on.
Posted by Garren Harland on August 19, 2009, 3:26 pm.
The Message Digest Algorithm designed by RSA Data Security, Inc. can help keep your user's passwords safe, even if for instance someone was capable of obtaining the user database with your passwords in them.
Click here to read on.
Posted by Garren Harland on August 19, 2009, 2:50 pm.
In a previous tutorial I have discussed the PHP function soundex(), and how it produces a 4 digit code that can be used to compare words that sound alike, but are spelt differently (such as Weather and Whether).
Click here to read on.
Posted by Garren Harland on August 19, 2009, 2:20 pm.
Previously I have discussed how rare symbols can be encoded and decoded from or into ASCII with the PHP functions html_entity_decode and htmlentities(). And while the function htmlentities() is perfect for converting non standard symbols into their ASCII equivalents, it does not convert every symbol out there.
Click here to read on.
Posted by Garren Harland on August 19, 2009, 1:21 pm.
Because of the various symbols that a URL will and might contain, such as colons, slashes, question marks and equals, passing them along as a Get variable is not possible in their original format. Some encoding is needed to make this smooth transition possible.
Click here to read on.
Posted by Garren Harland on August 19, 2009, 12:57 pm.
When passing along a URL as a Get variable, certain symbols need to be converted into a percentage sign, and a two digit hexadecimal equivalent of the corresponding ASCII symbol.
Click here to read on.
Posted by Garren Harland on August 18, 2009, 5:23 pm.
It can happen to anyone. You are looking for one search term, but instead of spelling it correctly you use a word that sounds similar, but is spelt slightly different. For instance you might be searching for the word "Weather" but have accidentally typed the word "Whether".
Click here to read on.
Posted by Garren Harland on August 18, 2009, 4:45 pm.
This tutorial will discuss how you can calculate the similarity of two strings in PHP. The returned value will be the match percentage, ideal therefore for search functions where results only need be displayed with a 50% plus match.
Click here to read on.
Posted by Garren Harland on August 18, 2009, 2:34 pm.
Building a spell check for your PHP applications may sound like a bit of a daunting task. The question of where to start may come up, as copying word for word out of countless dictionaries would seem to be a mind numbing task at least 99.9% of all programmers would love to avoid at all cost.
Click here to read on.
Posted by Garren Harland on August 18, 2009, 1:06 pm.
Ever asked yourself what the difference is between functions that start with the term ereg and eregi? After all, both search through strings by using regular expression patterns. Both either return true or false and pass on groups in arrays of regs (ereg and eregi), or perform a replacement in the specified location without changing the original (ereg_replace and eregi_replace).
Click here to read on.
Posted by Garren Harland on August 18, 2009, 11:20 am.
The PHP function sql_regcase() is ideal for regular expression newbies, as it converts any search patter with which it is provided into something a regexp function can use to analyse strings with.
Click here to read on.
Posted by Garren Harland on August 17, 2009, 7:28 pm.
Sometimes a string comes along that requires more than the traditional PHP split() function. Let us say for example we had multiple conditions by which a string needed to be split up by. In some instances a mere space would be enough, yet, the string should also be split up at each comma. Here then clearly a preg_split() is required.
Click here to read on.
Posted by Garren Harland on August 17, 2009, 6:43 pm.
Every asked yourself whether or not a symbol within a regular expression required a backslash, in order for the syntax to work? After all, there are quite a few symbols to keep track of in regards to regular expressions. Especially to programming newbies distinguishing between the two can be a daunting task.
Click here to read on.
Posted by Garren Harland on August 17, 2009, 5:08 pm.
Although regular expressions always look impressive, and are a good way of confusing non-programmers (and some programmers) while coming across as a rocket scientists, there are some instances when regular expressions are indeed not required. And validating a date is one of them.
Click here to read on.
Posted by Garren Harland on August 17, 2009, 4:17 pm.
Let's say you want to plan your Easter weekend for 2016. Naturally enough to do this you will require the exact date that Easter falls on. You can now do two things. Go look up the date in a calendar, or simply make use of a predefined PHP function capable of returning every Easter that has or will occur during the Unix era.
Click here to read on.
Posted by Garren Harland on August 17, 2009, 3:33 pm.
Let's say you have a variable named path, and all that you really require is the name of the file at the end of the path. Through some bizarre combination of programming functions and code structures you have also only been left with the path, and therefore have no way of singularly accessing the files name.
Click here to read on.
Posted by Garren Harland on August 17, 2009, 2:54 pm.
Disk space is one of those things most programmers rarely think about. Until the moment it is all used up that is! Lucky PHP has a function with the sole purpose of returning the amount of free disk space left within a specified location.
Click here to read on.
Posted by Garren Harland on August 17, 2009, 2:18 pm.
There are numerous reasons why a HTML file upload forms may fail to work. The most common errors are found in the coding of the HTML form itself. Based on this I will go through a short checklist for you to make sure that all the required elements are present in your HTML form before claiming that your host has done something wrong.
Click here to read on.
Posted by Garren Harland on August 8, 2009, 10:38 am.
Unless you are building a gangster rap forum, chances are that at least 50% of your visitors will not be too impressed by extensive swearing within posts. This however will not stop the other users from continuing to do so.
Click here to read on.
Posted by Garren Harland on August 7, 2009, 8:41 pm.
After you have received date from a textarea, unless you convert the line breaks into
tags, the data entered will all appear in one block. Luckily enough PHP already has a function to solve this problem. No complicated regular expressions are needed to solve this one;-).
Click here to read on.
Posted by Garren Harland on August 7, 2009, 8:26 pm.
Here is how you automatically start a file download once a user enters onto a page. Note, the user of course has to be willing to download the file, and can choose not to. If you are looking to force some software onto your visitors you are in the wrong place. If instead however you are looking for a simple download on load for an install shield for instance, carry on reading.
Click here to read on.
Posted by Garren Harland on August 7, 2009, 5:24 pm.
Most browsers plain and simple have not got a clue about how to deal with mp3 files. If you link to a PDF or word document they will play along, open a new window and display the document. Not so with MP3s. On your standard Internet Explorer (yes, even on version 8), it will just try to open the MP3 as a page, and will then give you an error message as if it was your fault for trying to give it an impossible task.
Click here to read on.
Posted by Garren Harland on August 5, 2009, 3:20 pm.
To calculate the remainder of a subscription time in PHP we need three items: the end date from the future in timestamp format, the current date in timestamp format, and a function to convert the difference between the two into something that is actually understandable to a human who's brain can not figure out how many days are within a given thousand seconds.
Click here to read on.
Posted by Garren Harland on August 5, 2009, 2:54 pm.
If you are looking for the value of a specific percentage of a number in PHP all you need is some basic maths. For instance, if you want to find out 5% of 100, simply multiply 100 times .05. Here are a few examples to try out.
Click here to read on.
Posted by Garren Harland on August 5, 2009, 2:33 pm.
Here is a useful bit of code for testing whether or not a number is dividable by a specified value. In our example below we will go through a "for" loop, checking every number to see if it can be divided by 5. If yes we will print it, if not we shall skip it and go on to the next.
Click here to read on.
Posted by Garren Harland on August 5, 2009, 10:28 pm.
On a dynamic website, such as a form, users often get the feeling they can post all kinds of dodgy images to their heart's desire. Now while most webmasters would either A. Let their visitors have their fun, or B. Go nuclear, and ban their visitors from interacting with HTML code, there is another way.
Click here to read on.
Posted by Garren Harland on August 4, 2009, 12:29 pm.
Previously I have discussed how to build a RSS feed and validate its structure. And while doing building and maintaining a RSS feed by hand is all well and good, usually they are an integral component of dynamic websites. Especially since the idea of an RSS feed is to constantly provide your readers with updates.
Click here to read on.
Posted by Garren Harland on August 3, 2009, 6:23 pm.
This page discuses how you can trick the PHP function mktime() into returning the Unix timestamp of a date within a specified distance in the future or from the past. To first illustrate this we will use the following example.
Click here to read on.
Posted by Garren Harland on August 3, 2009, 4:10 pm.
If you have a large dynamically generated array, you might need a function to find out if a specific element is contained within it. And the function that would come to your rescue in this scenario is in_array().
Click here to read on.
Posted by Garren Harland on August 3, 2009, 3:13 pm.
Sometimes all you need from a string are certain elements. Such an element can be a hidden number which has significance to you. Maybe a timestamp for instance.
Click here to read on.
Posted by Garren Harland on August 3, 2009, 12:24 pm.
The following function can be of significant value when used with other string manipulation functions. Although it is to be recommended that when outputting special characters in HTML, the ASCII equivalents should be used.
Click here to read on.
Posted by Garren Harland on August 3, 2009, 11:44 am.
If you have a string that can only contains alphanumeric values, it is a lot simpler to state the type of characters that are allowed, instead of looking up every possible symbol on the planet and banning it.
Click here to read on.
Posted by Garren Harland on August 3, 2009, 11:17 am.
When working with divisions the remainder is often required. This is often important for subsequent calculations, such as the conversion from seconds into days, minutes and hours.
Click here to read on.
Posted by Garren Harland on August 3, 2009, 10:15 am.
Most programmers go about this task the wrong way. Or rather they only complete half the job, and then wonder why they are not getting the intended results. Usually they do something along the lines of subtracting an old timestamp from the current one, which is actually a step in the right direction, but then they get frustrated when strftime() returns them some date from the 70s.
Click here to read on.
Posted by Garren Harland on August 2, 2009, 3:31 pm.
The error message discussed on this page is frequently due to a lack of understanding of how exactly header, and header related functions work. Indeed, often it is experienced after a function such as require_once() was used, and a document is called upon which tries to send of headers that are long gone.
Click here to read on.
Posted by Garren Harland on August 2, 2009, 2:25 pm.
In order to include a dynamically created PNG file into a HTML document we will need to create a separate PHP file. This file can then be included via a simple html image tag, specifying the PNG creating file.
Click here to read on.
Posted by Garren Harland on August 2, 2009, 12:13 pm.
If your website has a file upload facility, the last thing you will want is your visitors being able to upload any file to their hearts desire. Especially the upload of executable files could put a lot of your other users at risk if they chose to download it.
Click here to read on.
Posted by Garren Harland on August 1, 2009, 11:11 pm.
The php function filesize() will return exactly as the name indicates the size of a specified file. The following example will return the file size in a measurement of bytes.
Click here to read on.
Posted by Garren Harland on August 1, 2009, 7:24 pm.
If you need to dynamically create a directory in PHP, mkdir() is the function that you are looking for. All that it requires is a specified path to the folder that you want to create.
Click here to read on.
Posted by Garren Harland on August 1, 2009, 4:04 pm.
Using the function copy(), a file can be cloned to a specified destination. As the following example displays first the original file along with it's location needs to be provided, followed by a target location and name for the copied file.
Click here to read on.
Posted by Garren Harland on August 1, 2009, 1:04 pm.
With the PHP function chmod() you can modify a folder or files read, write and execute rights. This is done by first specifying the path and folder, followed by the according octal code. Three modes can be specified for each user group.
Click here to read on.
Posted by Garren Harland on August 1, 2009, 12:33 pm.
To return the path and name of a script with PHP the following two variables can be used. Both of them are server variables, which generally convey a lot of useful information on server details and settings.
Click here to read on.
Posted by Garren Harland on August 1, 2009, 11:27 am.
A decision every creator of an interactive website faces, is whether or not to allow their visitors to make use of HTML code, or the extent to which they can make use of it. After all, if you give users the option of posting their own HTML messages they might go a bit over the top and post something that does not at all fit in with your layout, or could even cause errors.
Click here to read on.
Posted by Garren Harland on August 1, 2009, 10:33 am.
Cached pages are any AJAX using programmer's worst nightmare. What use is a background news feed that is reloaded every 30 seconds if it constantly displays the same cached information? Clearly a forced update is needed!
Click here to read on.
Posted by Garren Harland on July 31, 2009, 8:05 pm.
Previously I have discussed how JavaScript enables us to automatically load a new location by editing window.opener.location.href. And while this method is very useful with pages that have already been loaded, and due to a given set of specified circumstances need to change location, it is not a very elegant way of conducting a simple re-direct.
Click here to read on.
Posted by Garren Harland on July 31, 2009, 5:39 pm.
In some instances obtaining an array's variables by themselves is not enough. Sometimes the belonging keys are also required. Here then is the easiest way to output both by using the PHP array functions list() and each().
Click here to read on.
Posted by Garren Harland on July 31, 2009, 4:38 pm.
As, the title indicates this page will discuss the PHP function split(), and how it can be used in a real world application. We will use an email invite function on a website as an example.
Click here to read on.
Posted by Garren Harland on July 31, 2009, 12:25 pm.
There is a relatively unknown function called parse_url(), which is ideal for evaluating links, and separating them into individual informative components. With the query string section of the URL being one of the more intriguing part. Here is a piece of code that demonstrates how parse_url() works.
Click here to read on.
Posted by Garren Harland on July 30, 2009, 8:03 pm.
One of the most powerful functions in php is eregi_replace(). By using this function effectively with good regular expression syntaxes you can manipulate strings to your heart's desire. On this page we will cover to simple examples as an introduction to eregi_replace(). If you have not worked with regular expressions before, you should definitely read the introduction to regular expressions tutorial before attempting the following examples.
Click here to read on.
Posted by Garren Harland on July 30, 2009, 5:57 pm.
Since the 1st of January 1970 the Unix clock has been ticking, one second at a time. Thanks to this every programmer has one time format from which all the others can be derived. In PHP this timestamp (with the current date, time, etc) can be loaded via the function.
Click here to read on.
Posted by Garren Harland on July 30, 2009, 5:12 pm.
Timestamps are great for the following reason. They can be converted into any chosen format without having to do much pre-converting. This saves a lot of time compared to times and dates stored in human readable formats.
Click here to read on.
Posted by Garren Harland on July 30, 2009, 4:26 pm.
Using the PHP function date() the current date and time can displayed numerous ways. Here then is a reference guide to help demonstrate these numerous formats and their respective codes.
Click here to read on.
Posted by Garren Harland on July 30, 2009, 1:34 pm.
Ever wanted to store every website a user has ever come through from to get an accurate picture of the origin of your traffic? While your stats tool may offer such a feature putting together your own table will give you a far more accurate insight as to where your visitors are coming from.
Click here to read on.
Posted by Garren Harland on July 30, 2009, 11:45 am.
The following variable can come in handy if you are attempting to write your own stats tool, or if you are merely interested in what type of browsers your visitors are surfing your site with. After all, for testing sake you might come across one or two rare browsers which you did not know about, and can therefore make sure that your website does indeed work as intended.
Click here to read on.
Posted by Garren Harland on July 30, 2009, 10:28 am.
If you are relatively new to PHP and not yet familiar with the concept of classes you are truly in for a revelation. Classes make the life of a programmer about 1 gazillion times simpler, help keep your code more organised (unless you are a master of untidiness), and most importantly in larger online applications help prevent variables from clashing.
Click here to read on.
Posted by Garren Harland on July 28, 2009, 10:59 am.
Dynamically swapping out the ;-), :-), :-( and other smilies shortcuts is as easy as it gets with PHP. All you need to do is perform a simple str_replace(), and in the brackets first specify the shortcut wink, and then after the comma place the image tag and files.
Click here to read on.
Posted by Garren Harland on July 25, 2009, 11:39 am.
Thanks to the GD Library Function ImageCopyResized() producing Thumbnails in PHP is not too difficult. The important part is what happens before that function to prepare the Image to be copied and resized.
Click here to read on.
Posted by Garren Harland on July 21, 2009, 5:17 pm.
Previously I have discussed how additions, subtractions, multiplications and divisions can be performed using bc functions with the results being produced to a specified decimal point.
Click here to read on.
Posted by Garren Harland on July 21, 2009, 4:57 pm.
Here are four PHP maths functions that might come in handy. If for instance you have to perform a simple addition, subtraction, division or multiplication, and want the result to be rounded to a specific decimal point, here is how you can do it.
Click here to read on.
Posted by Garren Harland on July 21, 2009, 4:13 pm.
All the FTP functions on PHP work similar to the command based interfaces such as the cmd on windows. So if you want to upload and manipulate a specific set of files, you need to be in that exact directory.
Click here to read on.
Posted by Garren Harland on July 21, 2009, 3:46 pm.
If you are building program for your users it goes without saying that it will need a rename function. We all have the habit of changing our minds on the names of files, folders, company names, even our own names in fact. And while ftp_rename() will not be able to change the name on your birth certificate, it can come in handy with files.
Click here to read on.
Posted by Garren Harland on July 21, 2009, 3:05 pm.
Here is a very fast and efficient way of adding various html tags to every element in an array using the PHP function array_walk(). If you have not encountered the function array_walk() before now you are in for a treat. Here is how it works.
Click here to read on.
Posted by Garren Harland on July 21, 2009, 2:19 pm.
One of the quickest and simplest ways to print out an array in PHP is by using the implode() function. Although it does not give you quite as much control as you may be used to from using loops, implode is ideal for situation where only a simple list is needed.
Click here to read on.
Posted by Garren Harland on July 21, 2009, 1:49 pm.
One of the most important components of a FTP program is the ability to output the name of every item inside a folder a long with its details such as.
Click here to read on.
Posted by Garren Harland on July 21, 2009, 12:26 pm.
If you are reading this I will assume that you are trying to access a MySQL Server from a remote host. Furthermore your remote server and your MySQL Server are not much in the mood for dancing, and no matter what you try you are confronted with this annoying error message.
Click here to read on.
Posted by Garren Harland on July 21, 2009, 12:26 pm.
Creating a new directory for a FTP program is a piece of cake. All you need to do is establish a connection with your server, and then go on and use the following function: ftp_mkdir()
Click here to read on.
Posted by Garren Harland on July 21, 2009, 12:14 pm.
If you are writing a FTP program with PHP you will at some stage need a function to provide you with the time and date when a file was last edited or uploaded. Lucky for us PHP already contains such a function: ftp_mdtm()
Click here to read on.
Posted by Garren Harland on July 21, 2009, 11:55 am.
Before you can download a file via FTP you will need to establish a connection to your server. So in case you do not know how to establish a connection, I would suggest you read the following tutorial first.
Click here to read on.
Posted by Garren Harland on July 21, 2009, 8:50 pm.
Before you can start uploading files via FTP in PHP you need to have established a connection with your server. This requires that you specify the correct server address, username, and password.
Click here to read on.
Posted by Garren Harland on July 16, 2009, 4:08 pm.
Before menacing users can be blocked their IP-Address needs to be captured and monitored. Here is one way to do so. Create a table called visitors into which you can store IP-Addresses.
Click here to read on.
Posted by Garren Harland on July 16, 2009, 3:21 pm.
If you are reading this page I guess you have been confronted with one of these and that you might be asking yourself why exactly the file you wish to be included is not being included. This is especially frustrated when you have finished a project on your localhost machine, proceed to upload your work with the expectancy of being able to bask in glory, only to be confronted with some annoying messages.
Click here to read on.
Posted by Garren Harland on July 16, 2009, 11:59 am.
If you are being confronted with this error message your code probably contains an endless/or seemingly endless loop at some point. The key then is to have a closer look at each of the loops in your code and making sure that they are indeed exit-able. The line number stated at the end of the Fatal Error message should give a hint as to whereabouts your code enters its viscous circle.
Click here to read on.
Posted by Garren Harland on July 16, 2009, 11:35 am.
The T_VARIABLE error message is usually a result of a typo, either caused by not closing off speech marks, or by having not defined a variable properly.
Click here to read on.
Posted by Garren Harland on July 16, 2009, 10:20 am.
While your average local development area is usually pretty lenient towards where you use the code session_start() most web hosts are not. Instead, the settings are usually set a bit stricter, and a few changes in your code are usually to be expected.
Click here to read on.
Posted by Garren Harland on July 13, 2009, 11:17 pm.
In order to convert negative numbers into positives in PHP one simple function is required: abs(). The abbreviation abs stands for absolute values, and works like this.
Click here to read on.
Posted by Garren Harland on July 13, 2009, 11:00 pm.
Here is a function that could come in handy with numbers games. More specifically: numbers games where the winner is the person who has guessed the closest number to an end result.
Click here to read on.
Posted by Garren Harland on July 13, 2009, 5:47 pm.
Uploading multiple files in PHP is not very different from uploading a single file. The only adjustment being that instead of one variable containing the files details, the variable $userfile_name for instance would become an array.
Click here to read on.
Posted by Garren Harland on July 13, 2009, 4:53 pm.
The amount of memory available to your scripts in PHP can be changed using one of the following three methods.
Click here to read on.
Posted by Garren Harland on July 13, 2009, 4:23 pm.
To change your web server's file upload limits with the following lines of code you may need to request the permission to do so from your host. This should be less of a problem if your website is located on an in house server.
Click here to read on.
Posted by Garren Harland on July 13, 2009, 1:00 pm.
This tutorial will teach you on the one hand how to convert decimal numbers into hexadecimals codes and vise versa, while at the same time having a closer look at the format of HTML Color codes.
Click here to read on.
Posted by Garren Harland on July 13, 2009, 10:42 am.
Here is the predefined PHP function that can calculate your square routs.
Click here to read on.
Posted by Garren Harland on July 12, 2009, 7:29 pm.
Connecting with and utilising a MySQL Database that is located on a different Server requires the same function with which connections are usually established in PHP: mysql_connect() (or mysql_pconnect).
Click here to read on.
Posted by Garren Harland on July 12, 2009, 6:42 pm.
The function array_splice() serves two purposes. On the one hand it can be used to remove certain elements from an array. Let us say for example we have an array that consists of 20 elements, using array_splice we could remove elements 10-15, turning our array into a 15 element array. Here is how it is done.
Click here to read on.
Posted by Garren Harland on July 12, 2009, 4:16 pm.
There are two functions that can be used in PHP to return the number of elements contained in an Array.
Click here to read on.
Posted by Garren Harland on July 12, 2009, 3:47 pm.
For this often required functionality PHP has two predefined functions to offer.
Click here to read on.
Posted by Garren Harland on July 12, 2009, 1:12 pm.
What better way to introduce the shuffle() an array function in PHP than using a stack of cards as an example? Like a good croupier however we won't just shuffle our cards using one method. Instead we will use a batch of functions including shuffle(), array_flip(), array_reverse(), array_slice() and array_merge().
Click here to read on.
Posted by Garren Harland on July 11, 2009, 8:50 pm.
The function asin() can be used to calculate the Sinus Arch in PHP. Simply insert the value in between the brackets and let PHP take care of the rest for you.
Click here to read on.
Posted by Garren Harland on July 11, 2009, 6:58 pm.
As with most mathematical requirements PHP already has a function in place to help deliver your results. And even for Cosine Arch calculations PHP is not a let down.
Click here to read on.
Posted by Garren Harland on July 11, 2009, 6:15 pm.
PHP has the constants mentioned in the title and others already predefined. All you need is the right code to access them by!
Click here to read on.
Posted by Garren Harland on July 11, 2009, 5:38 pm.
Are you tired of having to type [a-zA-Z0-9] every time you want your regular expressions to look for alphanumeric symbols? Then you are not alone! Thankfully an alternative method exists to address various shapes and forms of symbols in regular expressions.
Click here to read on.
Posted by Garren Harland on July 6, 2009, 6:40 pm.
BIC and SWIFT codes have a pretty simple format, and are therefore not that difficult to validate with PHP using regular expressions. Indeed, before we look into the regular expression itself, let us have a look at the build-up of a SWIFT/BIC Code. We will use the Swiss bank UBS' Code as an example: UBSWCHZH80A.
Click here to read on.
Posted by Garren Harland on July 6, 2009, 4:32 pm.
Here is a function that can be used to validate UK Postcodes using PHP and Regular Expressions. This code is a prime example of Regular Expressions method of validating a string from left to right. For instance, if AA99 is not checked for before AA9, our validation function would simply accept AA9 and would ignore any postcodes containing two numeric values at the end.
Click here to read on.
Posted by Garren Harland on July 6, 2009, 2:36 pm.
Here is how you find out if the current year is a leap year with PHP. The code date("L") will either return a 0 if it is not currently a leap year, or a 1 if it does happen to be one.
Click here to read on.
Posted by Garren Harland on July 6, 2009, 1:22 pm.
Are you tired of having your forum bombarded with spam? Then you might be interested in the code below. It first generates a random code, which is then converted into a PNG picture. Just embed the picture into your site and check to see if your new users/forum posters have entered the correct code.
Click here to read on.
Posted by Garren Harland on July 6, 2009, 10:48 am.
The following peace of code can be useful in the following two situations: 1.When a user of your site has reset their password. 2. When a user registers with your site and initially cannot choose their own password. Those are two situations within which this password generator can be used. It produces passwords consisting of random letters and numbers. Any recognisable words would therefore be a coincidence. And indeed meaningless passwords are the most secure type of passwords, when compared to sports teams or wife’s name and date and birth type passwords.
Click here to read on.
Posted by Garren Harland on July 4, 2009, 9:47 pm.
If you are like me you probably once upon a time spotted that PHP had a random number generating function called rand(), decided to save it to your memory, and left it at that. After all, a random number is a random number. Why would a programming language need more than one random number generating function?
Click here to read on.
Posted by Garren Harland on July 4, 2009, 8:57 pm.
Producing pi in PHP is even simpler than printing Hello World.
Click here to read on.
Posted by Garren Harland on July 4, 2009, 8:42 pm.
Previously I have written about the PHP function bindec(), and how it can convert a binary code into a decimal number. By reversing the function the opposite can be done, so changing bindec() into decbin() allows us to convert decimal numbers into binary code.
Click here to read on.
Posted by Garren Harland on July 4, 2009, 8:16 pm.
With the function bindec() you can translate a binary number into a decimal. Not that the largest convertible number (saved as a string) consists of 31 ones. This number equals the decimal value of 2147483647.
Click here to read on.
Posted by Garren Harland on July 4, 2009, 5:10 pm.
Looking for a PHP function to give you the greatest Common Divisor of two numbers? Then look no further. Although PHP does not as of yet provide such a function itself in its array of maths functions you can write a Greatest Common Divisor function yourself.
Click here to read on.
Posted by Garren Harland on July 4, 2009, 1:13 pm.
Are you in need of a PHP function that rounds numbers up to the closest integer? Then the function ceil() is your solution! Just insert the number that you need rounding up in between the brackets.
Click here to read on.
Posted by Garren Harland on July 3, 2009, 8:50 pm.
Do you need a PHP function to round down numbers down to the closest integer? Then floor() is the function you are looking for! To utilise the function insert the number that you need rounding down in between the brackets.
Click here to read on.
Posted by Garren Harland on July 1, 2009, 11:43 pm.
Removing duplicated values from an Array in PHP is simple. The function that we will be using to accomplish this task is: array_unique().
Click here to read on.
Posted by Garren Harland on July 1, 2009, 11:01 pm.
If you are working with PHP and MySQL, sooner or later you will no doubt require the id of an item you have just inserted into a table. Now, instead of having to perform an elaborate select statement to acquire the inserted items ID, there is a far more elegant solution.
Click here to read on.
Posted by Garren Harland on June 29, 2009, 12:27 pm.
Now while some might still be reading the title and asking themselves why on earth anyone would want to use PHP to gather data from a Microsoft Access Database, in the real world this type of functionality does make sense. Not using Access as a Database for a website of course. But it could well be that a company has stored a lot of data locally on an Access Database, and that the data is needed for the company's new website. Any programmer faced with this kind of task will thank his lucky stars that PHP is capable of hooking up with an Access database, and through this can load the data in question over to a MySQL, or other, more suitable database.
Click here to read on.
Posted by Garren Harland on June 29, 2009, 10:42 am.
A regular expression is a search a search pattern, that analyzes a string from left to right. Most symbols within a regular expression merely represent themselves, but there are a few that have specific meanings and cause the search pattern to act in a certain way.
Click here to read on.
Posted by Garren Harland on June 28, 2009, 2:42 am.
Ever wanted to jump to another section within your code? The goto operator included in PHP 5.3 gives you just that option. Note that this goto operator is not unrestricted. The target lable that you wish to jump to much be within the same function and file. You cannot jump out of a function, or indded leap into one. Jumping into a loop or switch is also not possible.
Click here to read on.
Posted by Garren Harland on June 27, 2009, 11:53 am.
When converting and manipulating data, whitespaces play an important role. Especially databases can fill up fields with the required number of empty spaces, which can lead to undesired effects in regard to sort functions. This is why the following three functions are of particular high value.
Click here to read on.
Posted by Garren Harland on June 26, 2009, 7:30 pm.
Do you need to validate user emails for your website? No problem. Here's how it is done using regular expressions.
Click here to read on.
myDesignTool Networking • www.mydesigntool.cominfo@mydesigntool.com