Я устанавливаю класс поиска для своего сайта, и я столкнулся с чем-то, и я понятия не имею, почему он не работает.
Вот класс
<?php
class search
{
public $location = array();
public $keywords = array();
/*
construct method
accepts $location and $keywords
*/
public function __construct($location, $keywords='')
{
$this->location = $this->format_location($location);
}
/*method format_location
accepts location value, determines its type... city, state, zip code
returns array of properly formatted location values
*/
public function format_location($input)
{
// check if location contains a zip code
$zip_pattern = "/\d{5}/";
$str = $input;
preg_match($zip_pattern,$str,$regs);
// if we do have a zip code lets put it in the location array
(!empty($reg[0])) ? $this->location['zip'] = $reg[0] : '';
// if we don't have a zip let's check for one of our pre=formatted locations, this will avoid unessesary regular expressions and database calls
if(!$this->location['zip']) {
$swinput = strtolower($input);
switch($swinput) {
case "chicago, il":
echo 'hello';
$this->location[] = array('zip' => 60601,
'city' => 'Chicago',
'state' => 'IL',
'lat' => '41.8781136',
'lon' => '-87.629798',
);
break;
case "naperville, il":
$this->location[] = array('zip' => 60564,
'city' => 'Naperville',
'state' => 'IL',
'lat' => '41.785863',
'lon' => '-88.147289',
);
break;
}
}
}
}
?>
итогда вот как я это называю
require("lib/search/class.search.php");
$lo = new search('chicago, il');
print_r($lo->location);
Проблема в том, что в свойстве location ничего не устанавливается.Есть идеи?