All Scripts backed by 10 years in business, free support, free updates and a 30 day money back guarantee.
Download Purchase Programming F.A.Q. Support Contact
Commercial Perl Scripts
All Form Pro Updated
Count It
Form Mailer + Attachments
Client File Manager
Da Godfaddah
Dropbox Updated
FAQ Builder
HT Manager Updated
RegisterHT
Mailing List Server
Page Updater - Text
Page Updater Pro Updated
PS Guestbook Updated
PS Lightning Search Updated
Quick File Mailer
Quick MySQL
Select-A-File
Upload Center
Free Perl Scripts
Access Log Viewer
All Form
Epoch Converter
Error Log Viewer
Invoice Center
PS Upload
Question Manager
Quick CHMOD
QuickHT
Site File Finder
Site File Lister
SSI Tag Maker
Perl Modules
Monger Calendar
Monger File
Monger Mail
Monger Persist
JavaScript Generators
PopUp Windows
Meta Gen
RGB / Hex Converter
Page Colors
Sudoku
Tutorials and FAQs
Cookies
Using CuteFTP
Using WS_FTP
Installing Scripts
Debugging
Utilities
env_vars.pl
backup.pl
restore.pl
check_email.pl
date.pl
dayname.pl
fileage.pl
format_length.pl
format_url.pl
getfile.pl
parse.pl
redirect_html.pl
Free Services
Epoch Converter
TLD Registries
RGB/Hex FInder
Colour Checker
ASCII Codes
Policies
Terms and Conditions
Privacy Policy
Refund Policy
Site Map

Form Processor with no SPAM from robots.

Anti-spam, anti-robot, anti-flame, Guestbook for your website.

Manage Remote websites from your website. Allow clients to update sections of their own web pages.

Secure file manager with upload progress meter. A printer's best friend. Find out more.

Utility Name: format_url.pl
Platform: UNIX or Linux
Requires: Perl4 or higher


If your programs require that the end users enter a url, you have to make sure it is being input in the correct format. Especially if this URL is going to be displayed on a webpage as a link. If the URL is not entered with the "http://" at the beginning, the link won't work. Try it for yourself and you will see that hypertext links don't work if there is no "http://" at the beginning of the URL.

This utility takes away the need for instructions to the user or for you to try and figure out the RegExp to check this. I've done it for you.

Here is how you use this utility:

Either cut and paste this subroutine into your own script or "require" this file by placing it in the same directory as your script and placing the following line anywhere before the subroutine is first called:

require 'format_url.pl';

Now you are ready to use it. The subroutine needs one parameter passed to it. This is the URL you want the format checked for. The subroutine will take any URL that does not have or is incomplete (ever typed "htp://www.foo.com" or "http:/www.foo.com" by mistake?) and return a properly formatted URL.

$good_url = format_url($check_url);

$good_url will be properly formatted: http://www.foo.com/whatever

What errors will it pick up? Here is list of what the subroutine will trap and correct:

  • www.foo.com
  • /www.foo.com
  • //www.foo.com
  • ://www.foo.com
  • p://www.foo.com
  • tp://www.foo.com
  • ttp://www.foo.com
  • http://www.foo.com

....or an combination of errors prior to the last forward slash.

Examples of valid calling formats:

$good_url = format_url($check_url);

$good_url = format_url("$check_url/$variable1/$variable2");

NOTE: This subroutine does not check to see if the referenced file actually exists, it only checks to see if the URL has the "http://" at the front of it.

S  T  O  P  !  !  !

This sub-routine does not support secure URL's. That is, URL's that have "https://" instead of "http://". Therefore, use your skills to create an alternate sub-routine to handle just secure URL's or if you are REALLY ambitious, use this sub-routine to create a new sub-routine that handles both secure and non-secure URL's. It's only mildly tricky!!
  ©2009 All rights reserved, PerlServices.net. Website hosting by LinuxHostingPlans.com