Inserting search terms into a search input in Drupal 7 When using Drupal 7, how do I print the current search terms into a search form in a block?

In Drupal 6, I used something like this in my template.php:

$vars['search_keys'] = search_get_keys();


Then, in search-theme-form.tpl.php I had:

&lt;input type="text" value="&lt;?php print $search_keys; ?&gt; name="search_theme_form" id="edit-search-theme-form-1"&gt;


But search_get_keys doesn't exist in Drupal 7, so I can't use this method.

Using arg(2) is the only method I've come up with, but that seems a little hacky, because it will break if the URL ever changes.
If you're using Apache Solr (http://drupal.org/project/apachesolr) you can use

$query-&gt;getParam("q")


in your search-result.tpl.php template.

Otherwise, you can use the slightly modified version of the function above:

function get_current_search_terms() {
// only do this once per request
static $return;
    if (!isset($return)) {
        // extract keys from path
        $path = explode('/', $_GET['q'], 3);
        // only if the path is search (if you have a different search url, please modify)
        if(count($path) == 3 &amp;&amp; $path[0]=="search") {
            $return = $path[2];
        } else {
            $keys = empty($_REQUEST['keys']) ? '' : $_REQUEST['keys'];
            $return = $keys;
        }
    }
    return $return;
}


edit: no need for check_plain here