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,477
  • 2
  • 21
  • 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,798
  • 64
  • 37
  • 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
  • 107,303
  • 21
  • 270
  • 254
leonxn
  • 1
0
urlencode(str_ireplace(array('+', ' ', '_', '.'), '-', $row['title']));
Vijay Arun
  • 414
  • 8
  • 15