Thursday, June 25, 2009

XML - Parse Indeed RSS Job Feed - PHP 5 required

It is easy to parse an XML feed with PHP 5 and simplexml_load_file(). Here is a form I created that will paste into any PHP 5 .php page. It grabs job results from and displays them on your site.

if (isset($_POST['query']))
$query = $_POST['query'];
$location = $_POST['location'];
$radius = $_POST['radius'];
$limit = $_POST['limit'];

$feedAddress = "".$query."&l=".$location."&limit=".$limit."&radius=".$radius."";

$indeedjobs = simplexml_load_file($feedAddress);

foreach ($indeedjobs->results->result as $jobs)
printf("JobName: %s\n", $jobs->jobtitle);
echo "<br>";
printf("URL: %s\n", $jobs->company);
echo "<br>";
printf("City: %s\n", $jobs->city);
echo "<br>";
printf("State: %s\n", $jobs->state);
echo "<br>";
printf("Country: %s\n", $jobs->country);
echo "<br>";
printf("Source: %s\n", $jobs->source);
echo "<br>";
printf("Date: %s\n", $jobs->date);
echo "<br>";
printf("Description: %s\n", $jobs->snippet);
echo "<br>";
printf("URL: %s\n", $jobs->url);
echo "<br>";
printf("OnMouseDown: %s\n", $jobs->onmousedown);
echo "<br>";
printf("JobKey: %s\n", $jobs->jobkey);
echo "<br>";
echo "<br>";
} else {
$query = '';
$location = '';
$radius = '10';
$limit = '50';
<form action="index.php" method="POST">
Search Jobs:
<input type="text" name="query" value="<?php echo $query; ?>" size="20">
<input type="text" name="location" value="<?php echo $location; ?>" size="20">
<select name="radius" id="radius">
<option value="1">1 Mile</option>
<option value="3">3 Miles</option>
<option value="5">5 Miles</option>
<option value="10">10 Miles</option>
<option value="15" selected="selected">15 Miles</option>
<option value="20">20 Miles</option>
<option value="25">25 Miles</option>
<option value="35">35 Miles</option>
<option value="50">50 Miles</option>
<option value="100">100 Miles</option>
<option value="4000">USA</option>
<option value="15000">World</option>
# Results:
<select name="limit" id="limit">
<option value="10">10</option>
<option value="25">25</option>
<option value="50" selected="selected">50</option>
<option value="100">100</option>
<input type='submit' value='submit' />

1 comment:

nima said...

Tried your code, doesnt seem to work, no results show up
Please test and comment