From The Blog

Shorten your URLs

2 June 2012, in

public function tinyURL($url = null) {
if ($url) {
return file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
} else {
return false;
}

}



Post a Comment

How to delete entire directory which is not empty in PHP

8 May 2012, in

In PHP to delete a file we use unlink() function,

and to delete a directory we use rmdir() function but the directory has to be empty first

Here is how to delete the entire directory whether it has files or not

function delete_directory($path){

$d = dir($path);

while($entry = $d->read()) {

if ($entry!= "." && $entry!= "..") {

if(is_dir($path.'/'.$entry)){

delete_directory($path.'/'.$entry);

}

else{

unlink($path.'/'.$entry);

}

}

}

rmdir($path);

}



Post a Comment

Detecting the iPhone and iPad

8 February 2012, in

Obviously, if you've created a page specifically for iPhone and iPad users, the first thing you'll need to do is to find out when a user is visiting your site via an iPhone or iPad. Apple provides the iPad's user agent string, which appears as follows:

Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10

The iPhone's user agent string appears as follows:



Post a Comment

FTP connections and file transfers

8 February 2012, in

$file = 'somefile.txt';
$remote_file = 'readme.txt';

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}

// close the connection
ftp_close($conn_id);



Post a Comment

Very helpful regex (regular expressions)

1 November 2011, in

Regular expressions are a very useful tool for developers. They allow to find, identify or replace text, words or any kind of characters. In this article, I have compiled 15+ extremely useful regular expressions that any web developer should have in his toolkit.

Getting started with regular expressions

For many beginners, regular expressions seems to be hard to learn and use. In fact, they're far less hard than you may think. Before we dive deep inside regexp with useful and reusable codes, let's quickly see the basics:



Post a Comment

Pages