Search box to advanced URL
I have a search engine on my site and the URL for the SERPs are search/QUERY/1/
.
How c开发者_StackOverflow中文版an I make an HTML search box to fill in the QUERY
section of my URL?
It can't really use PHP but it could use javascript if it has to.
using jQuery:
Live Demo
$('#search_button').click(function() {
var query = encodeURIComponent($('#search_query').val());
var searchurl = 'http://www.mysite.com/search/{query}/1/';
var newurl = searchurl.replace('{query}',query);
alert(newurl);
// $(location).attr('href',newurl);
});
<input type="text" id="search_query">
<input type="button" id="search_button" value="Search">
HTML :
<form action="index.php" method="post">
<input type="text" name="word" />
<button type="submit">Search</button>
</form>
index.php :
<?PHP
if( isset( $_POST['word'] ) )
{
header( 'location: /search/' . $_POST['word'] . '/' );
exit();
}
//Other index.php codes
?>
精彩评论