Character Type Functions PHP
Here I am listing a couple of Character Type functions, added to PHP in version 4.3.These functions test a given value against certain constraints for the current locale (established by the setlocale() function).
The Character Type functions provide validation specific to the given environment(i.e., the locale setting).
Function |
Checks If Value Contains |
| ctype_alnum() | Letters and numbers |
| ctype_alpha() | Letters only |
| ctype_cntrl() | Control characters |
| ctype_digit() | Numbers |
| ctype_graph() | Printable characters, except spaces |
| ctype_lower() | Lowercase letters |
| ctype_print() | Printable characters |
| ctype_punct() | Punctuation |
| ctype_space() | White space characters |
- Kiran's blog
- Add new comment
- Read more
- 393 reads
Running Server Commands in PHP
Here I will discussed how to run commands on the server. There are many PHP functions available for executing server commands.
For starters, there is exec():
exec(command, $output);
This function takes a command and assigns to $output an array where each
element is a line of the generated output.
There is also system(), which just returns the output (so that it could be immediately sent to the Web browser):
system(command);
The passthru() function is similar, but it can also return binary output:
passthru(command);
Finally, you could use shell_exec() or the backticks, both of which just return the output:
$var = shell_exec(command);
$var = 'command';
For security purposes, you should use escapeshellarg() or escapeshellcmd()
to sanctify any command that isn't hard-coded.
- Kiran's blog
- Add new comment
- 362 reads
Using Mail_Mime
PHP's built-in mail() function is simple to use, but it does have its shortcomings. For starters, you cannot use it with an SMTP server that requires authentication. Second, it’s not very easy to use it for sending HMTL email or email with attachments. A solution is to use PEAR’s Mail and Mail_Mime classes.
In layman’s terms, Mail_Mime turns the information you need to send—be it HTML or attachments—into the proper syntax for an email message. The Mail class is then used to send that message.
Sending HTML email
To start, you’ll need to include two class definitions (after having installed both PEAR packages, of course):
require_once (‘Mail.php’);
require_once (‘Mail/mime.php’);
You’ll also want to establish your message body. For HTML emails, you should create a plain text and an HTML equivalent. For the HTML content, it should be a complete HTML document:
$text = 'Plain text version';
$html = 'Your HTML part';
Now create a new Mail_Mime object:
- Kiran's blog
- Add new comment
- Read more
- 551 reads
Performing IP Geolocation PHP
Although the server where PHP is located could be anywhere in the world and the user could be located anywhere in the world, it is possible to make a geographic match. The premise is this:
- Kiran's blog
- Add new comment
- Read more
- 518 reads
Using PECL Filter
New in PHP 5 and quite promising is the Filter library of PECL code. Being developed by PHP’s creator and other major contributors, the future of Filter looks bright, even though it’s still in beta form (at the time of this writing). The Filter package provides two types of security:
◆ Data validation by type
◆ Data sanitization
What Filter offers is a unified interface for performing common types of validation and sanitization. For example, I might commonly use code like this:
if (is_numeric($_GET[‘id’])) {
$id = (int) $_GET[‘id’];
if ($id > 0) {
// Do whatever.
}
}
}
I could instead do this:
if ($id) { …
//Dow whatever.
}
- Kiran's blog
- Add new comment
- Read more
- 452 reads













