PHP Tutorial : Validate email address – simple way with filter_var() function

While browsing php.net without any scope I discovered a very cute & nice way to replace the usual regular expression email checking thing.
That way is via filter_var() php function which does the things 10 times faster :

<?php
$email = “someone@example.com”;

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo “Invalid email address”;
}
?>

Read PHP Tutorial : Validate email address – simple way with filter_var() function »

Dynamically create an image from any text in PHP

My goal when I did this quick script was to use php to convert text into images, so that email addresses could be dynamically inserted into pages, making spam harvesters’ life a little harder.
Of course it has many more uses, one of them being to avoid web spiders from fetching a specific word…………….

Read Dynamically create an image from any text in PHP »

Find Browser Name and Capabilities in PHP

To get the browser name just use this line:

<?php
print $_SERVER['HTTP_USER_AGENT'];
?>

And to get all the browser’s features use:

<?php
print_r(get_browser(null, true));//null for user agent and true to receive an array

?>

Read Find Browser Name and Capabilities in PHP »

PHP Tutorial : Country list array

In my point of view, a very useful and common thing we need when we build for example a membership site it’s country list array. I will do it within next function then will show how to use it :
Click here to get the function
And here’s how to use it for example to generate a…………….

Read PHP Tutorial : Country list array »

PHP Tutorial : List function

Beeing surprised that I didn’t write here about this “cute” php function called list(). I like it a lot, it’s like the extract() function in some way if you remember.
The list() php function will assign variables in one shot to strings from arrays.

<?php
//here's the php array

$countingArray = array(1,2,3);
//here, the list function will convert 1 to…………….

Read PHP Tutorial : List function »

PHP Tutorial : Get Protocol

I saw this problem/question on a few forums and I finded it useful to post on my blog too due to low results on google that gives you what you need. So,  how to get the protocol of a URL using php?  Have a look :

<?php
$protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))==’https’?'https’:'http’;

print “The protocol is $protocol”;
?>

Tadaaa!

Read PHP Tutorial : Get Protocol »

PHP Tutorial : Ctype character type checking

Happy 1st June for those under 18
Yesterday I’ve found a nice function in php called ctype. And? What it does? Well, I see it as a replacement for regular expressions. PHP Ctype function checks for character type. Let’s hear the chars type we can check with that nice function  :

alphanumeric characters – ctype_alnum()
alphabetic characters     …………….

Read PHP Tutorial : Ctype character type checking »

PHP Tutorial : Get line number

As you might know, PHP Server comes with built-in / already defined constants. Today I’ve been discovering a nice one which gets the line number in a file for you. This may be very usefull in a lot of cases, like a custom error system, debugging and not only. That CONSTANT is called simply _LINE_

<?php

print…………….

Read PHP Tutorial : Get line number »

PHP Tutorial : Extract function

A shame for me but I must tell you this function called extract() simply rocks : it will extract “keys” from an array and convert them into variables, so no more needed to manually declare variables for validation purposes from forms.

<form action="" method="post">
name <input type="text" name="name"><br/>
email <input type="text" name="email"><br/>
<input type="submit" name="sb" id="sb" value="go">
</form>
<?php

if(isset($_POST['sb'])) {
extract($_POST);

if(empty($name) ||…………….

Read PHP Tutorial : Extract function »

PHP Tutorial : Create a RSS / XMLS Feed

Welcome,
In this tutorial I will show you how to create a basic rss / xml feed with php. Basically, if you know how to create a feed in notepad, wordpad or whatever text editor, this will be easy. The difference between creating a php xml / rss feed and a “normal” one it’s that you…………….

Read PHP Tutorial : Create a RSS / XMLS Feed »