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,457
  • 2
  • 16
  • 19

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
  • 4,967
  • 63
  • 33
  • 38
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
  • 97,531
  • 20
  • 242
  • 238
leonxn
  • 1
0
urlencode(str_ireplace(array('+', ' ', '_', '.'), '-', $row['title']));
Vijay Arun
  • 398
  • 9
  • 13