Login or Register Now   Email:  Password:   

Get Relative Root

PHP provides functions to get the webserver document root within the $_SERVER super global array, and for getting the current working directory with the getcwd() function. But it often occurs that the document is being served from another directory within the web tree. This function will get the current working directory, relative to the web server document root.

Read More

Substr In Array

To find if a value exists in an array, the PHP in_array() function works quite nicely. But there are times when only a partial match is required to check in the array. This substr_in_array() function checks will search the values of an array for a substring. The $needl can be a string or an array of strings to search for

Read More

Convert Numbers To Roman Numerals

Roman numerals can add a bit of pizzaz to a site or be used in legal documents or even for giving a site a touch of gladitorial grace. This function will convert a number to a roman numeral that can be used anywhere on a site.'

Read More

Atomic Time

Here is a function to fetch the Atomic Time from an online atomic clock. When the right time is crucial in an application, and the time on the server clock cannot be trusted or is incorrect, this function will provide assurance the the time is correct.

Read More

Rainbow Text

A litte helper function to make your site emo2.0 compliant. This site will convert text into rainbow text. The text is colored in various colors to give swirling colored effect if used in long text strings.

Read More

Find Position Of Nth Occurrence Of String

The PHP functions that search strings do a fine job of finding the first of last occurance of a search string. But what if the task was to find the second or third occuance of a string within a string. This function provides an offset parameter to find the Nth occurance of a string within a string.

Read More

Get Domain Name From URL

This function will extract the domain name from a URL. The url can be any valid URL containg the scheme and hostname. The function will discard other information and return only the http://www.phpro.org portion of the URL string.

Read More

Alternating Row Colors

Displaying tabular data from arrays and database results often make use of a table with alternating row colors. This simple example shows how alternating row colors can be used to make every second table row a different color.

Read More

Google Maps With PHP And Phproogle

The PHPRO phproogle class allows PHP developers to quickly create Google Maps without needing to bother with the mind boggling Google Maps API. This class allows developers to create a Google Map using on PHP and the phproogle class will take care of the rest

Read More

Recursively Rename All Files In Directory With RecursiveDirectoryIterator

The PHP SPL Iterators are used in this function to efficiently recurse through a directory and rename the files within. By using the RecursiveDirectoryIterator and the RecursiveIteratorIterator the recursion is done by PHP and there is no need to be writing recursive functions within the code base.

Read More

Get Text Between Tags

PHPRO.ORG recieves many requests for solutions to every day problems. The most popular request is to find the text between two tags. These may be HTML body tags or XML tags or other. This function will get the text between tags of any named tag. This enables the user to specify any tag and the function will return the text inside.

Read More

Convert Photoshop PSD File With Imagick

Sometimes a user needs up upload a photoshop PSD file to a site. With the PHP Imagick extension the power of ImageMagick can be employed to convert the photoshop PSD file into a JPG, PNG or any other image format supported by ImageMagick.

Read More

Parse HTML With PHP And DOM

For many, the process of parsing varibles out of HTML tables has been a hard grind with numerous regular expressions and string functions. This example code shows how to parse HTML with PHP using the DOM extension to gain the values of data stored within the HTML table.

Read More

First Day Of Month

The first day of the month function does exactly as you would expect, it fetches the first day of the month. The default behavior is to default to the current month, but an optional parameter allows for fetching of the first day of any month, any time.

Read More

Strip Single Tag

The PHP strip_tags function allows for the stripping of tags and excludes the ones to be maintained. This function allows the user to specify exactly which tags to be stripped, and all others are maintained. The option is available to strip a single HTML or XML tag also. Very handy if stripping of only a single, or more tags is required.

Read More

Days Of Week Dropdown

A dropdown menu list for use in forms or calander class or wherever days of the week are required. The days and numbers have been assigned as per ISO-8601 to give the greatest compatibility with other calendar systems.

Read More

Month Dropdown List

Here is a function to create an HTML dropdown list of months. Handy for use in form classes or any script where you need to display a dropdown month list like a calander class. Two options are provided for this function, demonstrating different approaches and different speeds.

Read More

Days Between Two Dates

This function provides a simple and effective method of counting the number of days between two dates. An option is also provided to return partial days also. This function does not calculate years or months or seconds, only days. Ideal for countdown scripts and the like.

Read More

Validate Email By Regular Expression

Latter day PHP versions have the benifit of validating email address using the filter_var function from the filter extension. For those who dont have access to filter var, or simply prefer to do things with a regular expression, this function will validate most email addresses using a simple regular expression.

Read More

Recursive In Array

Recursively search a multi-dimensional array for any occurrance of a string. This function works in the same way as the PHP function in_array except this function works on single dimensional or multi-dimensional arrays. An option is also provided to check for type.

Read More

Create Columns From Array

Creating columns from an array or from a database result set can seem a little tricky. The key to making it happen is the PHP modulo operator. With some simple math, database result sets and arrays can be rendered in two, three, four or more columns.

Read More

Convert Seconds To Words

This function takes a UNIX TIMESTAMP as generated by strtotime or from any source and converts it into a human readable notation. Convert seconds to words is a function that should be done at the application level and not from from SQL queries as this may interfere with display logic.

Read More

Create-Test-Database

Here is a small but useful script to create test data for databases. Two test tables are created with PDO and filled with various data types including Binary (BLOB) data.

Read More

80000 Word List

Some times you just need a list of words, a big list. Here is a list of about eighty thousand words to help with.. well whatever!

Read More

Radians To Degrees

This function complements the Degrees to Radians functions by doing exactly the opposite, converting radians to degrees. Handy for those geographical calculations need when plotting points on a map with with online applications such as google maps or yahoo maps.

Read More

Degrees To Radians

Here is a handy function for those messing with goe location and geo targetting or other geo graphical toys. This function convert degrees to radians for use in map plotting etc.

Read More

Get Riemann Distance

This function will calculate the distance between two points on the earth using the great circle distance formulae. This function should not be used to calculate linear distances, instead use the GetLinearDistance function. This function will return a value in miles, nautical miles or kilometers

Read More

Get Linear Distance

This function calculates the linear distance between two points. Give to x1 y1 x2 and y2. This is not a function for calculating distances between latitudes and longitutes, for that purpose see the Get Riemann Distance function.

Read More

US Cities Zip Codes

Ever needed a comprehensive list of US cities, zip codes, latitude and longitude? Well you can pay up to $100 dollars for one or you can use this database of over forty one thousand (41000) cities and their locations. Great for geo targetting and geo location in your next application.

Read More

Get Full URL

A PHP function to get the full url of a web page. This function gathers several of the PHP super globals to create the whole URL.

Read More

Get Link Text

Ever wanted to get the text component of a URL. Not the link destination but the link itself. Well you search is over because the work has been done for you.

Read More

Calculate How Many Years Old

This function will work out how many years old you are based on a date provided in any format that is readable by strtotime. The function itself returns an integer of how many year old minus months day etc.

Read More

Convert BMP to JPG

The PHP GD library lacks the ability to convert BMP images to JPG. This can be achieved with the Imagick extension but for those folks with only GD at their disposal, this function will get you through the day.

Read More

Convert Unix Timestamp To MySQL Timestamp

Here is a quick but useful function to convert PHP time to MySQL times. That is, UNIX TIMESTAMP to MySQL TIMESTAMP format. Handy for all those times you need to deal with changing date formats.

Read More

Create Horizontal Gradient With PHP Imagick

The PHP Imagick extension allows for the creation of gradients. By default these gradients are vertical. This example code provides a method of creating horizontal gradients using simple rotation.

Read More

Password Strength Tester

PHP Security is an important part of creating forms. Recently there has been a proliferation of password strength testing scripts about, each with their own algorithms for checking the strength of passwords. This example shows how it is done.

Read More

Twenty Four Hour to Twelve Hour

Converting 24 hour time to 12 hour can be a hassle when you have different formats. This helper function takes 24 hour times and converts them to its 12 hour counterpart. Fun for all ages.

Read More

58000 Words

58000 Words is a MySQL table containing just what it says, over 58000 words in a MySQL dump so you can stick it directly into your database for use in your applications. Great for any time you need a word list to match against.

Read More

Directory-Size

When you need to get the size of an entire directory using PHP this function will give you result in Bytes. You can then do the math to format it into KB or MB or whatever format you like.',

Read More

PDO to Array

Here is a small utility function that takes the result of a PDO query using a key value pair and creates a single dimensional array from it.

Read More

Imagick Thumbnail From Center

This thumbnailer script is a little different from many by allowing the user to crop from the center of an image instead of the everyday resizing that pollutes the net

Read More

PHP Xajax Loading Message

This example shows how to use PHP and Xajax to create a Loading message while a server task is being processed. Handy for those occasions when you do not need a progress bar. More on the progress bar later.

Read More

PHP Xajax Accordian

This PHP Xajax script builds on the PHP Xajax Sliding Draw example and creates a great effect without any more knowledge of javascript than your socks.

Read More

PHP Xajax Sliding Draw

Ever needed a naf slideout draw to show and hide content but did not know enough javascript to get past hello world? me either, but with a little Xajax and PHP the job is little more than a chore.

Read More

Change Style with Xajax and PHP

For those new to xajax and PHP, here is a simple script to get you started. It shows how to change a divs style and content using xajax to call a PHP function.

Read More

Get All URLs From Page

I needed to get all the urls from a string. So I came up with this little function to do that. It will also get all the urls from a web page if you so desire.

Read More

wordbreak

Here is a useful PHP script that breaks a string at the last whole word before a specified number of characters. Great for news snippets or forums where you have a read more link etc.

Read More

Insert At Array Index

Here is a little helper function if you need to insert an array at a given index. Very useful when creating stuctured data for use in XML or CSV files, or any structure.

Read More

Flatten Array

This little helper is just what you need to flatten a multidensional array into a single level.

Read More

Count Lines in File

Often times we need to count the number of lines in a file. There is a right way and wrong way of achieving this goal. This is one of the right ways.

Read More

Array Values Similar

When the time comes that you need to be sure all the values of an array are identical, this little function will get you on the way.

Read More

Sanitize Email

As the internet expands, so do the amount of contact forms. Quite often these contact forms are exploited by spammers to send out millions of mails every year. Here we see how to make sure your contact form is not one of them.

Read More

First Words

Here is a NAF script to grab the first n number of words in a string. The number of words is variable to suit you application.

Read More

Lower Case an Array

Ever needed to change the case of all the elements in an array? This function shows how it is done.

Read More

Format Date

As a request to a phPro user, this function was created to format a UNIX timestamp with the default value as the current timestamp, then set the default timezone also.

Read More

Country Array

This handy array provides a list of country names and thier two letter country code as the array keys. Keep this one bookmarked.

Read More

Array Push Assoc

Read More

Random Password Generation

Read More

Convert Numbers to Words

Read More

Variable Variables

Read More

Write Text To Image

Read More

URL to Link

Read More

Variable number of arguements

Read More

Re-index Array

Read More

Text to Image with GD

Read More

PHP Tag Cloud

Read More

Push element onto the beginning of an array

Read More

Percentage match strings with PHP

Read More

PHP SERVER SUPER GLOBAL

Read More

Parse Camel Case

Read More

Parse Domain

Read More

List all variables

Read More

Multiple file upload

Read More

Generate Bar Graph with PHP and GD

Read More

Get File Extension

Read More

Delete Line From File

Read More

Example of destructor

Read More

Cut a deck of cards with PHP

Read More

Encode Email

Read More

Convert tai64 to timestamp

Read More

Create Anagrams

Read More

Convert Seconds to Numbers

Read More

Collapse Whitespace

Read More

Combine two arrays

Read More

Benchmark or time script

Read More

Check if number is Odd or Even

Read More

Abstract-Class-Example

Read More

Apache Log Date

Read More