php - How to insert the search query string in an anchor -
let's take 3 keywords: sunlight, mirror, eclipse
when doing search using form:
<form method="get" action="search.php"> <input name="q" type="search"> </form>
the url looks nice, this:
http://localhost/gallery/search.php?q=sunlight+mirror+eclipse
so far good.
when trying insert search query string in anchor, this
// query string if (isset($_get['q'])) { $current_q = $_get['q']; } <a href="<?php echo 'http://localhost/gallery/search.php?q=' . $current_q; ?>">this query</a>
i ugly weirds characters in between keywords, this:
http://localhost/gallery/search.php?q=sunlight%20mirror%20eclipse
why? , how make nice, when using form?
thanks
the easiest way use $_server['query_string']
after ?
in same way url getting it
http://localhost/gallery/search.php?q=sunlight+mirror+eclipse
some code
<?php $query = $_server['query_string']; $query = str_replace(' ', '+', urldecode($query)); echo "<a href='http://localhost/gallery/search.php?$query'>this query</a>";
Comments
Post a Comment