Creating a distance between cities using the geolite data that I’ve used in the the mapping IP-2-Location. If you look at longitude and latitude points in decimal format instead of the degrees:min:seconds then you can pretty much figure out how you calculate distance. Its the same way you do when you measure the distance between two points on a sphere.

Surprisingly, php has no support that I know of to convert degrees to radians, so I first built that, then the rest is just self explanatory.

“The world is a book and those who do not travel read only one page.” - St. Augustine

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
33
34
35
36
<?php
// no native function in php4/5
function toRadians($degrees) 
{
    return $degrees * pi() / 180; 
}
$lat1 = $_POST['lat1'];
$lat2 = $_POST['lat2'];
$lon1 = $_POST['lon1'];
$lon2 = $_POST['lon2'];
$R = 6371; // km radius of earth
$dLat = toRadians($lat2-$lat1);
$dLon = toRadians($lon2-$lon1); 
$a = sin($dLat/2) * sin($dLat/2) +
        cos(toRadians($lat1)) * cos(toRadians($lat2)) * 
        sin($dLon/2) * sin($dLon/2);
$ax = 1-$a;
$c = 2 * atan2(sqrt($a), sqrt($ax)); 
$d = $R * $c;
?>
<html>
	<body
	<div >
	<?= 'Distance:'.$d ?
	</div>
	<div>
		<form action="" method="post">
		<fieldset><label>Lat1</label><input type="text" name="lat1" size=4></fieldset>
		<fieldset><label>Lat2</label><input type="text" name="lat2" size=4></fieldset>
		<fieldset><label>Lon1</label><input type="text" name="lon1" size=4></fieldset>
		<fieldset><label>Lon2</label><input type="text" name="lon2" size=4></fieldset>
		<input type="submit">
		</form>
	</div>
	</body>
</html>
Our Sponsors

AJAX and PHP combined together in a simple chat message server.  This uses XMLHTTPRequest to call itself with the appropriate GET variables to trigger a read or write to a server-side file named chit-chat.dat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
<?php
$filename = 'chit-chat.dat';
 
if(isset($_GET['msg'])){
$msg = sanitize($_GET['msg']);
$conv = file_get_contents($filename);
file_put_contents($filename,$conv.$msg);
exit;
}
if(isset($_GET['conv'])){
$conv = file_get_contents($filename);
echo $conv;
exit;
}
function sanitize($var){
//sanitize here
return $var;
}
?>
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
33
34
35
36
37
<script type="text/javascript">
 
function createXMLHttpRequest() {
if (typeof XMLHttpRequest != "undefined") {
return new XMLHttpRequest();
} else if (typeof ActiveXObject != "undefined") {
return new ActiveXObject("Microsoft.XMLHTTP");
} else {
throw new Error("XMLHttpRequest not supported");
}
}
 
function sendMsg(msg){
request = createXMLHttpRequest();
request.open("GET", "index.php?msg="+msg, true);
request.onreadystatechange = function() {
//
}
request.send(null);
}
function rcvMsg(){
request = createXMLHttpRequest();
request.open("GET", "index.php?conv=1", true);
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
var node = document.createTextNode(request.responseText);
document.getElementById("output").appendChild(node);
}
}
request.send(null);
}
rcvMsg();</script>
 
<div id="output">
 
</div>
<input type="text" id="msg_form"><input type="submit" value="send" onClick="sendMsg(document.getElementById('msg_form').value);rcvMsg();">

Craigslist is an interesting marketplace and is a bit behind the times technology wise.  Many people enjoy the simple interface and easy to understand style, however if you try to use craigslist for more than your local area you might encounter a huge time expense.  Craigslist helper which is on google search has a nice little feature to help you search multiple places at once.

I decided it couldn’t be all that hard to do this especially considering craiglist’s incredible rss search ability.  So with the download of magpierss to do the rss parsing it was really just a matter of bring it together.

With out further ado, craigslist job query

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
require_once('rss_fetch.inc'); //magierss
 
	$subdomains = array('atlanta','austin','boston','chicago','dallas'
,'denver','houston','lasvegas','losangeles','miami','minneapolis',
'newyork','philadelphia','phoenix','portland','raliegh','sacramento',
'sandiego','seattle','sfbay','washingtondc');
	$query = 'fudge'; // your query here
 
	foreach($subdomains as $skey=>$subdomain){
		$url="http://$subdomain.craigslist.org/search/jjj?query=$query&format=rss";
		$rss = fetch_rss( $url );
 
		echo "<h2>$subdomain : " . $rss->channel['title'] . "</h2>";
		echo "<ul>";
		foreach ($rss->items as $item) {
			$href = $item['link'];
			$title = $item['title'];
			$desc =  $item['description'];
			echo "<li><a href=$href>$title</a><p>$desc</p></li>";
		}
		echo "</ul>";
	}
?>

We shall neither fail nor falter; we shall not weaken or tire…give us the tools and we will finish the job.
Winston Churchhill

Next Page »