Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2002
    Location
    Top Secret
    Posts
    14,135

    Character decoding, anyone help?

    Ok, I'm a bit stumped here, and could use some help trying to figure this one out.

    I'm in the process of importing helpdesk entries from one piece of software to another. That part, for the most part is reasonably easy. The problem I'm seeing, however is that this helpdesk software is storing these entries using some sort of encoding (at first I thought it was utf-8, but I'm stumped now). I've written a bit of a function to decyper this stuff, but it would be NICE to actually figure out what this was, if anyone can.. Here's a bit of what the entries look like in the sql db.

    Updating+%2Fscripts+...%0ASync+Source%3A+http%3A%2F%2Fhttpupdate.cpanel.net%2FRELEASE%2Fscripts%0AFetching+http%3A%2F%2Fhttpupdate.cpanel.net%2Fcpanel sync%2FRELEASE%2Fscripts%2F.cpanelsync.lock+%280%29....%40198.66.78.12......connected......receiving...100%25......Done%0AFetching+http%3A%2F%2Fhttpup date.cpanel.net%2Fcpanelsync%2FRELEASE%2Fscripts%2F.cpanelsync.bz2+%280%29
    The function I've written to (somewhat) clean this up:
    PHP Code:
    function cleanup($string)
    {
    $string=str_replace('%0D''<br \>'$string);
    $string=str_replace('%0A''<br \>'$string);
    $string=str_replace('%2F''/'$string);
    $string=str_replace('%7D'')'$string);
    $string=str_replace('%7B''('$string);
    $string=str_replace('+',' '$string);
    $string=str_replace('%3A',':'$string);
    $string=str_replace('%5B','['$string);
    $string=str_replace('%5D',']'$string);
    $string=str_replace('%2C',','$string);
    $string=str_replace('%3B',','$string);
    $string=str_replace('%40','@'$string);
    $string=str_replace('%3D','<'$string);
    $string=str_replace('%3E','>'$string);
    $string=str_replace('%3F','?'$string);
    $string=str_replace('%5C%5C%5C%27','\''$string);

    return 
    $string;

    Now, can someone, ANYONE tell me a better way to do this? Is this actually utf-8 and I'm missing something in the utf8_decode process? I'm stumped here, any help would be appreciated
    Tom Whiting, WHMCS Guru extraordinaire
    Linux problems? WHMCS Problems? Give me a shout
    Check out my WHMCS Addons

  2. #2
    Join Date
    May 2004
    Location
    NYC
    Posts
    793
    The string is a url-encoded string. Use the php urldecode() function to replace the + sign with a space, #XX with meaningful characters, etc:

    Code:
    $string = urldecode($encoded_string);
    online php manual reference page is here: http://us3.php.net/manual/en/function.urldecode.php

  3. #3
    Join Date
    Sep 2002
    Location
    Top Secret
    Posts
    14,135
    Aye, url-encode it was. I knew there was something stupid I was missing somewhere. Thank you!!!!
    Tom Whiting, WHMCS Guru extraordinaire
    Linux problems? WHMCS Problems? Give me a shout
    Check out my WHMCS Addons

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •