meandme
meandme

Reputation: 2477

Using urlencode in mysql row php

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

Answers (3)

Vijay Arun
Vijay Arun

Reputation: 414

urlencode(str_ireplace(array('+', ' ', '_', '.'), '-', $row['title']));

Upvotes: 0

user2730567
user2730567

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

leonxn
leonxn

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

Related Questions