Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6371257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:02:21+00:00 2026-05-25T01:02:21+00:00

I am setting up a search class for my site and I’ve run into

  • 0

I am setting up a search class for my site and I’ve run into something and I have no clue why it’s not working.

Here is the class

<?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;
            }

        }

    }

}

?>

and then this is how I’m calling it

require("lib/search/class.search.php");
$lo = new search('chicago, il');
print_r($lo->location);

Problem is that nothing is getting set in the location property. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:02:21+00:00Added an answer on May 25, 2026 at 1:02 am

    Try to use

    /*
    construct method
    accepts $location and $keywords
    */
    public function __construct($location, $keywords='')
    {
        $this->format_location($location);
    
    }
    

    instead of

    $this->location = $this->format_location($location);
    

    Because format_location doesn’t return anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: public class Search { private Desktop desktop = new
Alright...I've given the site a fair search and have read over many posts about
I have few search forms and each form has an input value with class
This question follows on from this vim search question I have a setting in
We have a static html/webform site, the site lacks search functionality, I was able
I am setting up a Solr Search Engine that will index multiple languages. I
Background: I have a managed object, Car. I have a RESTful search API sitting
Setting up the sandboxes for all these option is not feasible right now. So
When setting up Google Adsense or Gmail as a site owner, you are required
I have created a custom MembershipProvider class, so far so good, however, I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.