I’m making a site to learn coding and am making a search site. The search is $q.
$q = ucwords(mysql_real_escape_string(trim($_REQUEST['q'])));
Then I am trying to put a link to other words the user might want to search. Unfortunately, if a word is “Example & Another Example”, $q is only “Example”, and the rest is left out. In the url this works (as in nothing is left out) example+%26+another+example
but this doesn’t work Example%20&%20Another Example
.
I tried using str_replace to replace all of the & with %26 but it just made the $q = null. What’s the issue?
Here’s my code:
echo "<hr /><span><strong>Refine Search</strong><br/><br/>";
$result = mysql_query("SELECT * FROM subcat WHERE catnumber='1' LIMIT 0,10");
$subcaturl = str_replace("&", "%26", $row['subcat']);
while($row = mysql_fetch_array($result))
{
echo "<a href='search.php?q=". $subcaturl ."'/>" . $row['subcat'] ."</a>";
echo "<br />";
}
Try urlencode: