添加间距在字符串上点击锚标记和显示在下一页url与间距


Add spacing in string on click on anchor tag and displaying in next page url with spacing

我有一个锚标记,如下所示。

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

我想要的是,当我点击这个链接时,它应该跳转到下一页url应该变成,

nextpage.php?name=Nike-Baby-Shoes

但我不知道如何在字符串中放置间距,而在url中显示。现在网址是nextpage.php?name=Nike%20Baby%20Shoes .

请指导我怎么做

最好的方法是在输出链接时使用PHP替换空格。例如:

$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>";