Forum Moderators: coopster

Message Too Old, No Replies

convert funny HEX into CHAR

how in php?

         

smallcompany

8:14 pm on Nov 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



When the script grabs $_SERVER['HTTP_REFERER'], and writes it down into a text file, or passes parts of it as a variable, those HEX characters make it look really bad.

I looked online and see no straight (short code) option, or I was not able to recognize it.

Does PHP provide anything that can convert this quickly?

For example - instead of having %2f I would like to see simple /

Thanks

jdMorgan

8:18 pm on Nov 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See the PHP urldecode function.

Jim

smallcompany

8:25 am on Nov 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



And that was just it...

Thanks very much!

TheMadScientist

11:56 am on Nov 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The urldecode() page of the manual doesn't make it very clear, so I thought I'd point out to make sure you have a look at rawurldecode() too...

urldecode() converts + symbols in the string to spaces, while rawurldecode() converts %20 to spaces, but not + symbols.

IOW: rawurlencode() and rawurldecode() convert to and from RFC 1738 compliant URL strings respectively, while urlencode() and urldecode() do not, so the structure of the information being passed should determine which is used to get the correct decoding from the string you are receiving.

smallcompany

5:58 am on Nov 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



urldecode() converts + symbols in the string to spaces

I see that in the flat file where I write this stuff. Thanks very much.

I'll check the suggested function...

jdMorgan

2:24 pm on Nov 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should also consider what "agent" was used to encode the URL in the first place. If you use urlencode in your scripts to generate links, then you will likely want to use urldecode as the "mirror function" to decode these linked URLs when requested by a client. However, if you rely on the browser to encode your links, then rawurldecode may be more appropriate when decoding client-requested URLs.

The good news is that you get a choice... :)

Jim

smallcompany

5:10 pm on Nov 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



decoding client-requested URLs

Thanks.

All what I do is grab referring URL to get some basic data and let it go.

I switched it to urldecode() to omit plus signs converted to spaces just so the log file looks better in Notepad++

And based on the research, that "+" is the only difference between the two.