Inserting search terms into a search input in Drupal 7
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