Categories

Match an email address

$match = ‘/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/’;

preg_match($match, $email);

Shortcode example

<?php function my_example()
{
return ‘hello world shortcode example’;
// or echo
}
?>
<?php add_shortcode(‘mytest’, ‘my_example’);?>

Then add [mytest] to the post.

Use a specific font

This example shows how to use a specific font.

<?php header("Content-type: image/gif"); $image = imagecreate( 500, 250 ); $blue = imagecolorallocate($image, 0,0,255 ); $font = "ARIALBD.TTF"; [...]

What version of PHP

I was asked how to get the version of PHP , this was due to the minimum requirements of a script stating PHP 5 and  a user wanted to know how he could check what his host supplied.

This is the simplest version, save as version.php, upload and  then open it in your web browser.

<?php
echo phpversion();
?>

On [...]

Is IP valid

function ValidIP($ip){

if (preg_match(‘/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/’, $ip)){
return true;
}

return false;
}

FTP file upload example

upload a single file to a FTP server

// FTP access parameters
$host = ‘ftp.myftp.com’;
$usr = ‘username’;
$pwd = ‘password’;

// file to move:
$local_file = ‘./example.txt’;
$ftp_path = ‘/data/example.txt’;

// connect to FTP server
$conn_id = ftp_connect($host, 21) or die (“Cannot connect to host”);

// send access parameters
ftp_login($conn_id, $usr, $pwd) or die(“Cannot login”);

// perform file upload
$upload = ftp_put($conn_id, $ftp_path, $local_file, FTP_ASCII);

// check upload [...]