Skip to content
WJunction - Webmaster Forum

php urlencode problem

Status
Not open for further replies.

mahjong

Established Member
238
2010
14
Hi all!

I'm trying to create an a to z listing on my wordpress site. The letters are altering mysql query (with hyperlink and get method) so it would return only posts starting with the letter clicked by user.

The problem is that i have characters that should not be in urls (É,Ő, etc). So, of course, the solution should be urlencode... end here comes the problem: (example)

PHP:
$letter="É";
$encodeit=urlencode($letter);

echo "<a href='./?letter=".$encodeit."' >Letter is: $letter </a>";
So, my problem is with this code: the browser (both firefox and chrome) always decodes automatically the encoded letter. If i just echoing the encoded letter, i get the needed values (like %C5%90) but if i pass them to a hyperlink (so user could click them) the browser automatically decodes it (if i open the source of the page, it is encoded there too, but if i click on the hyperlink, it opens the hyperlink with the decoded character.)

What should i do?

ps.:
So, for example, the created hyperlinks source code (not the above letter)
Code:
<a href="./?page_id=157&amp;betu=%C5%90"><span class="azheadletter">So in the source code everything is all right</span></a>
But after clicking on it, in the browser bar, the letter is decoded (and if i'm echoing the get parameter on the hyperlinked page, i get back the decoded character, not the encoded)
 
Last edited:

4 comments

Well, i do not bother with iit anymore, it has something to do with the browsers. I just urlencoded and then urldecoded the get hoping it will work properly for others too...
 
Data in $_GET and $_REQUEST encoded with urlencode() are alutomatically decoded.
I'm not sure if it works, but anyway try the alternative function: rawurlencode() .
 
Last edited:
Status
Not open for further replies.

About the author

M
Established Member · Joined
238
Messages
14
Reactions
206
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom