1

I have an anchor tag like as follows.

<a href="nextpage.php?name=Nike Baby Shoes">shoes</a>

What I want is, when I click on this link, it should go to next page and url should become like,

nextpage.php?name=Nike-Baby-Shoes

But I am not aware about how to put spacing in string while displaying in the url. Right now the url is coming like nextpage.php?name=Nike%20Baby%20Shoes.

Please guide me to do that.

Jenz
  • 8,280
  • 7
  • 44
  • 77
user3615820
  • 45
  • 1
  • 8

1 Answers1

0

Your best bet is to just replace the spaces using PHP, when you output the link. For example:

$name = "Nike Baby Shoes";  // or use whatever variable you get the name from

$replaced = urlencode( str_replace(' ', '-', $name) );

echo "<a href='nextpage.php?name={$replaced}'>shoes</a>";
Cully
  • 6,427
  • 4
  • 36
  • 58