Ben
Ben

Reputation: 1914

Convert '%23' to '#' in PHP

URL: example.com/search:#searchWord

Since the # is not send to the server, it is changed to %23.

In the search page I want to display

Results for: #searchWord

But what I get is %23searchWord. I tried htmlspecialchars(), but nothing happens.

Upvotes: 0

Views: 5968

Answers (2)

Bibhas Debnath
Bibhas Debnath

Reputation: 14939

echo urlencode('example.com/search:#searchWord');
// output: example.com%2Fsearch%3A%23searchWord

echo urldecode('example.com%2Fsearch%3A%23searchWord');
// output: example.com/search:#searchWord

Upvotes: 1

Aurelio De Rosa
Aurelio De Rosa

Reputation: 22162

To achieve your goal use urldecode.

Upvotes: 3

Related Questions