Reputation: 2477
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
Upvotes: 0
Views: 2802
Reputation: 414
urlencode(str_ireplace(array('+', ' ', '_', '.'), '-', $row['title']));
Upvotes: 0
Reputation: 11
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']));
Upvotes: 1
Reputation: 1
You can use this :
urldecode(str_replace("+", "-", $row['title']))
urldecode(str_replace(" ", "-", $row['title']))
urldecode(str_replace("_", "-", $row['title']))
urldecode(str_replace(".", "-", $row['title']))
Upvotes: 0