Note that there are some explanatory texts on larger screens.

plurals
  1. POExtract $keyword from a php search form
    text
    copied!<p>Here is my search function :</p> <pre><code>class Ads extends Controller { public function search($format='velos', $cat='occasion', $location='france', $keyword, $page=1) { if($format == 'velos') { $query = '`private`=0'; } else { $query = '`private`=1'; } $this-&gt;images($query, $cat, $location,'MATCH(title) AGAINST ("'.db::escape($keyword).'" IN BOOLEAN MODE)', $page, '%s/%s/%s/'.$keyword.'/%d/', $row[0], $keyword); } } </code></pre> <p>It's working fine, when I change the keyword in the URL, everything is okay But I would like to echo that keyword in the page, I don't know how ? I tried </p> <pre><code>&lt;?php echo $keyword; ?&gt; </code></pre> <p>But the echo doesn't return anything. There might be a scope issue, but I'm not sure.</p> <p>EDIT Actually the $keyword comes from a search field, but from another class, that's maybe why I was thinking of a scoping issue</p> <pre><code>class UserModel extends Model { public function search_form() { $form = new Form('search_form'); $form-&gt;field('keyword', 'text', array ( 'optional' =&gt; true )); if($data = $form-&gt;validate()) { header('Location: '.WEB.sprintf($data['parts_search'].'/'.$data['category_search'].'/'.$data['location_search'].'/'.$data['keyword'].'/1/')); } return $form; } } </code></pre> <p>Solution : </p> <p>It might not be the best solution, but actually the only one I found :</p> <pre><code>$url = 'http://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $parts = parse_url($url); $path = $parts['path']; $keys = explode('/', $path); echo $keys[4]; // `corresponding to the 4th url word` </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload