0

I get some data from the database then create a link from the data.

<a href=\"news/people/" . urldecode($row['title']) . ".html\" target=\"_self\">"

the output is link is http://wwww.website.com/news/people/ask+question+stack.html so instead of having the plus sign in the link i will like to hve a link with hyphen like this http://wwww.website.com/news/people/ask-question-stack.html

Thanks for the help Newbie

meandme
  • 2,467
  • 2
  • 18
  • 20

3 Answers3

1

It should be URL Encoding not URL Decoding when building a link with content from a database. if the content in $row['title'] = "ask question stack", then you could replaces spaces with hyphens and then encode your string.

urlencode(str_replace(' ', '-', $row['title']));
slavoo
  • 5,437
  • 64
  • 35
  • 39
0

You can use this :

urldecode(str_replace("+", "-", $row['title']))
urldecode(str_replace(" ", "-", $row['title']))
urldecode(str_replace("_", "-", $row['title']))
urldecode(str_replace(".", "-", $row['title']))
interjay
  • 101,717
  • 21
  • 254
  • 248
leonxn
  • 1
0
urlencode(str_ireplace(array('+', ' ', '_', '.'), '-', $row['title']));
Vijay Arun
  • 406
  • 10
  • 14