OpenCrypt - Membership Software
Sale now on! 10% off everything!
Username:
Password:
Register / My Account / Forgotten Password?
 Home  Features and Benefits  Online Demonstration  Purchase  Our Services  Help and Support  my.OpenCrypt 
 Welcome  New Visitor  Latest NewsRSS Feed Company Information  Press/Testimonials  Frequently Asked Questions  BlogNew Content
PHP: Basic functions for quickstart PHP framework
Wednesday 30th April 2008

Below are a number of PHP functions which we hope you will find useful when developing your applications, all are very simple functions but each takes a minute to write, and hopefully we can save you that minute!
 

1. Numeric Validation
Check the variable $number is a number/integer.
 

 
Usage
print validate_number("10");
Or
$number = "10";
print validate_number($number);


2. Regular Expression and Alphanumeric Validation
Check the variable $string matches a regular expression or for example, is alphanumeric, e.g. only contains letters and numbers.
 

 
Usage (default - alphanumeric)
print validate_regex("1 String of Text");
Or (default - alphanumeric)
$string = "1 String of Text";
print validate_regex($string);
Usage (alpha)
$string = "One String of Text";
print validate_regex($string,"/[^a-zA-Z ]/");
Usage (alpha - lowercase only, no spaces)
$string = "onestringoftext";
print validate_regex($string,"/[^a-z]/");


3. Email Address Validation
Check the variable $email is a valid email address.
 

 
Usage
print validate_email("email@address.com");
Or
$email = "email@address.com";
print validate_email($email);


4. URL Validation
Check the variable $url is a valid web site URL.
 

 
Usage
print validate_url("http://www.OpenCrypt.com/");
Or
$url = "http://www.OpenCrypt.com/";
print validate_url($url);


5. URL text to linked HTML
Find text URLs in string and replaces with linked HTML URL. e.g. 'Please go to: http://www.OpenCrypt.com/' would become 'Please go to: http://www.OpenCrypt.com/'
 

 
Usage
print url_string_to_html("Please go to: http://www.OpenCrypt.com/");
Or
$string = "Please go to: http://www.OpenCrypt.com/";
print url_string_to_html($string);


6. UK Postcode Validation
United Kingdom postal code validation, fully tested post code function including validation for two postal codes which do not fit traditional formats, notably GIR0AA and TDCU1ZZ.
 

 
Usage
print validate_postcode("AA000AA");
Or
$postcode = "AA000AA";
print validate_postcode($postcode);


7. Random String Generation
Generate a random string, useful for password and session ID generation.
 

 
Usage (20 character string)
print generate_string(20);
Usage (10 character string, custom characters A to E, 0 to 9)
print generate_string(10,"ABCDEF0123456789");


8. Strip HTML Tags
Remove/strip HTML tags from string/variable, extremely useful for filtering inputs.
 

 
Usage
$text = "<html><head></head><b><u>hello world</u></b></html>";
$tags = array("html", "body", "head", "u");
print strip_selected_tags($text, $tags);


All Functions in One File
This text area includes all of the above functions in one ready to go PHP file, simply copy and paste and save as [something].php. This field also includes the license for the above functions which is of course Open Source.
 

 
Share this article:
Delicious Stumble It!
Stumble It!
 
<- Press Release: OpenCrypt 2.0 in Development!
 
Welcome to the OpenCrypt Blog! ->
Articles
Subscribe to RSS Feed
Website Pre-Launch Checklist
ionix in 2010
PHP Security Tips - Part 1
OpenCrypt 1.8 New Feature Highlights
Video Conversion API
We're on Twitter!
IP Location API
Integrating OpenCrypt's PHP Login Interface
Developing Mobile Web Sites
Service Recovery
Building relationships with your customers
Doing the unexpected
PHP/JavaScript World Map with Continent and Ocean Selection
We've Moved!
Customer Showcase: A-Z-Animals.com
Optimising your secure content for Google
Membership business models
AJAX Calendar with PHP and mySQL
PHP Function for Reciprocal Linkback Checking
AJAX Tree Menu with PHP - Revisited
What is membership software?
Login form designs and inspiration
PHP subscriber counter with Addicted to Feedburner class and Feedburner Awareness API
AJAX Tree Menu with PHP
AJAX data listings engine with PHP and mySQL (BETA)
Join the ionix Team!
Press Release: OpenCrypt 2.0 in Development!
PHP: Basic functions for quickstart PHP framework
Welcome to the OpenCrypt Blog!
Visitor Comments
Ratna Colluru 10 out of 10
Space Holder
Thank you for sharing these code snippets.
Thank you
Ratna Colluru

Space Holder
Space Holder
Average Rating: 9.81 out of 10 (226 Votes)
Space Holder
Submit Comment
Space Holder
Article Rating:
Space Holder
Your Name:
Space Holder
Your Comment/Response:
Space Holder
Space Holder
Space Holder

Follow us on Twitter

Copyright © 1999 - 2010 ionix Limited. Affiliates, Contact Us

Powered by OpenCrypt Membership Software, Backups by myRepono Website Backup