WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Checking for valid (or lack thereof) input.
Categories : PHP, Perl Update Picture
Brian J.
Date : Jul 23rd 2000
Grade : 5 of 5 (graded 1 times)
Viewed : 2903
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Brian J.
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

It amazes me how many developers just use something along the lines of:

if($var != '')

to check for an empty value.

Yet, if someone just hits the spacebar, $var won't be empty, and will appear OK to the above
conditional.

Whitespace has value people. For that matter, so do newlines and tabs (\n and \t,
respectively, along with a few more (consult your languages' manuals. They are, almost, the
best friends you have as a programmer).)

In PHP, use trim() to hack off whitespace, then use empty() to make sure it's, you guessed it,
not empty.

http://www.php.net/manual/function.trim.php
http://www.php.net/manual/function.empty.php

In Perl use something like:

if($var !~ /^\s*$/)

And, of course, always filter your input, when your data will be coming from an outside source,
to ensure that you'll get exactly what you're looking for.

For PHP, there are a host of terrific functions for this purpose. Check them out:

http://www.php.net/manual/ref.strings.php

For Perl (CGI), you will most certainly want to enable Taint checking. Stick the -T switch at the
top of your script/application:

#!/usr/bin/perl -T
use strict;

You'll see errors, and it's in your best interest to learn what they mean.




Checking to see if a file exists with PHP
Categories : PHP, Filesystem, Perl
How would s/(http:\/\/.*?) /<a href=$1> $1 <\/a>/g; look in php?
Categories : PHP, Perl, Regexps
STR - a Perl-like string manipulator class - The str class provides 4 perl-like methods for manipulating strings and other scalar variables.
Categories : PHP, PHP Classes, Perl, Strings
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use!
Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP
PHP Object Example of the Perl DBI with MySQL
Categories : PHP, PHP Classes, MySQL, Databases, Perl
Retrieve text from table and email to your e- address in pipe delimited format.
Categories : PHP, MySQL
Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs.
Categories : Databases, PHP, MySQL, Complete Programs
A PHP function to encrypt and decrypt a number or string or a combination of the two.
Categories : PHP, Encryption, Security
Using $PHP_AUTH_USER and $PHP_AUTH_PW to authenticate.
Categories : Authentication, PHP
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
Authorize.net AIM Interface Class v1.0.0
Categories : PHP, PHP Classes, Ecommerce, Payment Gateways
Cut your MySQL Connections to 1 line of code
Categories : PHP, Beginner Guides, Databases, MySQL
A simple class with some HTML output functions that would come in handy for consistent page layout etc.
Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation
recode -- Recode a string according to a recode request
Categories : PHP, PHP Functions, Recode