Category Archives: Uncategorized

How to retrieve Google Backlinks count with PHP

Here's a simple script to retrieve the approximate number of backlinks Google has for a site. The function and how to call it follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function get_google_backlinks_count($url) {
	$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:$url"
 
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_REFERER, 'http://www.yoursite.com/');
	$response = curl_exec($ch);
	curl_close($ch);
 
	$json = json_decode($response);
	return $json ->; responseData ->; cursor -> estimatedResultCount;
}
 
echo get_google_backlinks_count('yahoo.com');
[ad]

Simple PHP script for unzip function

Here’s a simple PHP function to unzip a ZIP file and retain directory structure – great for use when you can’t use exec(). The function will return false on error and true on success. Call it with the following code:

1
2
3
4
if (unzip('../mtm.zip'))
	echo 'Cool, it worked!';
else
	echo 'Uh oh, something went wrong.';
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function unzip($zipfile) {
	$zip = zip_open($zipfile);
	if ($zip) {
		while ($item = zip_read($zip)) {
			$name = zip_entry_name($item);
			if (substr($name, -1) == '/') {
				if (!file_exists($name)) {
					$dir = mkdir($name);
					if (!$dir) {
						zip_close($zip);
						return false;
					}
				}
			} else {
				if (zip_entry_open($zip, $item, "r")) {
					$f = file_put_contents($name, zip_entry_read($item, zip_entry_filesize($item)));
					zip_entry_close($item);
					if ($f === false) {
						zip_close($zip);
						return false;
					}
				} else {
					zip_close($zip);
					return false;
				}
			}
		}
		zip_close($zip);
		return true;
	}
	return false;
}
[ad]

How to Duplicate Database Rows in MySQL

If you're looking for a quick, easy way to duplicate a MySQL Row, try the following example:

1
2
3
4
5
6
INSERT INTO Tbl1
		(Col2, Col3, ...)
	SELECT
		(Col2, Col3, ...)
	FROM Tbl1
		WHERE Col1 = 1;

This example assumes you want to duplicate the row where Col1 equals 1. You could change the where clause to anything for that matter. However, if there are more than one rows selected from the SELECT statement, it will INSERT each row, not just one.

Likewise, you could duplicate a whole MySQL table using the following:

1
2
3
4
5
INSERT INTO Tbl2
		(Col2, Col3, ...)
	SELECT
		(Col2, Col3, ...)
	FROM Tbl1;
[ad]