tags:

views:

140

answers:

2

hi

I sent a text via GET method to decode html entities ( w = w )

> ?text=w&type=htmldecode&format=text

I got errors in the $text variable then I tried to set it in the last of the link

?format=text&type=htmldecode&text=w

and I got the same errors

how I can fix that ?

+2  A: 

I think you need to decode it then re-encode it using URL encoding urlencode

oykuo
+3  A: 

There are 2 types of encoding pertinent to your problem. HTML escape characters, and URL escape chars.

When you have a character in an HTML page, you use the HTML escape characters. eg

w = w

But you cannot use those characters in a URL - & and # have special meanings in URLs. So you have to encode again - this time using URL escape characters.

# = %23

& = %26

; = %3B

So your string, ('w') fit to be put into a URL, would be:

%23%26119%3B

and your entire query string:

?text=%23%26119%3B&type=htmldecode&format=text

the aforementioned PHP urlencode() does this.

The snippet:

<?php echo urlencode("&#119;"); ?>

outputs

%26%23119%3B

rascher