Welcome Guest, Not a member yet? Register   Sign In
Post your controller!
#19

[eluser]Jay Logan[/eluser]
Here is a function that is part of one of my internet portals that let's me check the position a web site is in Google results.

Code:
function find_google_position()
    {
        $this->load->helper(array('dom', 'date'));
        $this->load->library(array('form_validation', 'typography'));
        
        $this->form_validation->set_rules('url', 'URL', 'trim|required|prep_url');
        $this->form_validation->set_rules('keywords', 'Keywords', 'trim|required');

        if ($this->form_validation->run() == FALSE) {

            redirect('admin/tools/google_positions');

        } else {

            $keywords = str_replace(' ', '+', $this->input->post('keywords'));

            $html = file_get_html('http://www.google.com/search?q='.$keywords.'&num=100&start=0');
            $new_lines = array("\t","\n","\r");
            $content = str_replace($new_lines, "", html_entity_decode($html));
    
            $results_array = $html->find('h3.r');
            
            foreach ($results_array as $result) {
            
                if (substr($result->find('a', 0)->href, -1) == "/") {
                
                    $clean_results_array[] = substr($result->find('a', 0)->href, 0, -1);
                
                } else {
            
                    $clean_results_array[] = $result->find('a', 0)->href;
                    
                }
    
            }
            
            foreach ($clean_results_array as $key => $value) {
            
                if ($value == $this->input->post('url')) {
                
                    $position = $key + 1;
                
                }
            
            }
    
            $google_position_info['url'] = $this->input->post('url');
            $google_position_info['keywords'] = $this->input->post('keywords');
            
            if (isset($position)) {
            
                $google_position_info['current_position'] = $position;
                
            } else {
            
                $google_position_info['current_position'] = "Not within top 100.";
            
            }
                
            $google_position_info['date_added'] = time();
            
            $this->tools_model->add_google_position($google_position_info);
            redirect('admin/tools/google_positions');
            //print_r($clean_results_array);
        }

    
    }


Messages In This Thread
Post your controller! - by El Forum - 08-30-2009, 12:19 AM
Post your controller! - by El Forum - 08-30-2009, 01:36 AM
Post your controller! - by El Forum - 08-30-2009, 07:19 AM
Post your controller! - by El Forum - 08-30-2009, 12:31 PM
Post your controller! - by El Forum - 08-30-2009, 12:44 PM
Post your controller! - by El Forum - 08-30-2009, 08:59 PM
Post your controller! - by El Forum - 08-30-2009, 10:07 PM
Post your controller! - by El Forum - 08-31-2009, 02:13 AM
Post your controller! - by El Forum - 08-31-2009, 03:13 AM
Post your controller! - by El Forum - 08-31-2009, 03:19 AM
Post your controller! - by El Forum - 08-31-2009, 04:43 AM
Post your controller! - by El Forum - 08-31-2009, 04:49 AM
Post your controller! - by El Forum - 09-01-2009, 01:05 AM
Post your controller! - by El Forum - 09-01-2009, 09:30 PM
Post your controller! - by El Forum - 09-02-2009, 02:42 AM
Post your controller! - by El Forum - 09-02-2009, 05:34 AM
Post your controller! - by El Forum - 09-02-2009, 09:02 AM
Post your controller! - by El Forum - 09-02-2009, 09:43 AM
Post your controller! - by El Forum - 09-02-2009, 10:13 AM
Post your controller! - by El Forum - 09-02-2009, 01:13 PM
Post your controller! - by El Forum - 09-03-2009, 06:40 AM
Post your controller! - by El Forum - 11-03-2009, 10:20 PM
Post your controller! - by El Forum - 11-03-2009, 11:02 PM
Post your controller! - by El Forum - 11-03-2009, 11:33 PM
Post your controller! - by El Forum - 11-04-2009, 12:09 AM
Post your controller! - by El Forum - 11-04-2009, 03:36 AM
Post your controller! - by El Forum - 11-04-2009, 07:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB