NYCPHP Meetup

NYPHP.org

[nycphp-talk] Converting hex?

Rob Marscher rmarscher at beaffinitive.com
Wed Sep 6 11:02:56 EDT 2006


That's pretty slick!  However, if you have any plus signs (+) in your 
string, they'll get converted to a space.  Not sure if there are any 
other unintended side effects.  Not exactly sure if it performs better 
or not to do it your way...  But anyway, thanks for sharing.  That's a 
clever solution.
-Rob

Jeff Loiselle wrote:
> Rob,
>
> I ended up doing this:
>
> $response = str_replace('\x', '%', $response);
> $response = urldecode($response);
>
> That did the trick. :-)
> /jeff
>
> On 9/5/06, Rob Marscher <rmarscher at beaffinitive.com> wrote:
>   
>> Did you figure this one out?
>>
>> Try
>>
>> $data - file_get_contents($some_remote_https_url);
>> $pieces = explode(',', data);
>> print preg_replace("/(\\\x[0-9A-Fa-f]{1,2})/e", "chr(hexdec('\\1'))", $pieces[0]);
>>
>> Seems to do the trick.
>> -Rob
>>
>> Jeff Loiselle wrote:
>>     
>>> Anyone know of a nice efficient function to convert this?
>>> $name = 'Tony D\x27Antonio';
>>>
>>> I realize that putting it in double quote will do it, but I am unable
>>> to do that. As I am doing something like this:
>>>
>>> $data - file_get_contents($some_remote_https_url);
>>> $pieces = explode(',', data);
>>> print $pieces[0];
>>>
>>> Output:
>>> Tony D\x27Antonio
>>>
>>> This doesn't seem to help:
>>> print "$pieces[0]";
>>>
>>> I'm looking for the most efficient way, as this is being used in a
>>> REST response parser. Thanks!
>>>
>>> ---
>>> Jeff Loiselle
>>> Web Developer
>>> The NewNewMedia Group
>>> http://www.newnewmedia.com
>>> _______________________________________________
>>> New York PHP Community Talk Mailing List
>>> http://lists.nyphp.org/mailman/listinfo/talk
>>>
>>> NYPHPCon 2006 Presentations Online
>>> http://www.nyphpcon.com
>>>
>>> Show Your Participation in New York PHP
>>> http://www.nyphp.org/show_participation.php
>>>
>>>
>>>       
>> _______________________________________________
>> New York PHP Community Talk Mailing List
>> http://lists.nyphp.org/mailman/listinfo/talk
>>
>> NYPHPCon 2006 Presentations Online
>> http://www.nyphpcon.com
>>
>> Show Your Participation in New York PHP
>> http://www.nyphp.org/show_participation.php
>>
>>     
>
>
>   

-- 
Rob Marscher
Software Engineer
rmarscher at beaffinitive.com
212.684.9100x17




More information about the talk mailing list