title: JQuery ui autocomplete with codeigniter
body: <p>OK, I am trying to use autocomplete with codeigniter. I did this exact method using regular HTML, JQuery and php an it worked. I tried to modify a bit to make it work with codeigniter but its not working.</p>
  
  <p>The JQuery</p>
  
  <pre><code>$("#update-text").autocomplete({source:"&lt;?php echo site_url('userProfile/autocomplete');?&gt;",dataType:"json"});
  </code></pre>
  
  <p>The function autocomplete in userProfile controller</p>
  
  <pre><code>function autocomplete(){
      // this takes the text field and whatever the user writes it autocompletes it.
      //Every single place and event in the database should be displayed in this view in this format
  
  
  
      $this-&gt;load-&gt;view("source", $data);
  
      }
  </code></pre>
  
  <p>The form in the php file</p>
  
  <pre><code>&lt;form method="post" action="#" name="updatePlanForm"&gt;
  &lt;div class="ui-widget"&gt;
  &lt;label for="update-text"&gt;&lt;/label&gt;
  &lt;input type="text" id="update-text" name="updateText" value="What are you gonna do today?" onclick="removeText()"/&gt;
  &lt;/div&gt;
  &lt;input type="button" class="small green button" value="Update Plan" name="updatePlanButton"/&gt; &lt;!-- once clicked JQuery sends a post to a controller send_plan and jquery will return the view --&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and finally the source php file</p>
  
  <pre><code>&lt;?php
  
  $req = $_GET['term']; //first get the search keyword as get method
  
  $arrResults = array('orange', 'apple', 'bannana');
  
  $array = array_filter($arrResults, 'mycallback');
  //filter the array containing search word using call back function
  
  function mycallback($var)
  {
      global $req;
      if(preg_match('/^'.$req.'/', $var))
      {       
          return $var;
      }
  }
  
  $array1 = array();
  
  //filter null array
  foreach($array as $arr =&gt; $val)
  {
          if(!empty($val))
          {
                  $array1[] = $val;
          }
  
  }
  
  //echo out the json encoded array
  echo json_encode($array1);
  
  ?&gt;
  </code></pre>