Search results for 'URLEncode'. 2 post(s) found.

  1. 2009/03/24 URL Encode, Decode function for MFC
  2. 2007/10/11 Is there URLEncode function in Javascript ?
2009/03/24 08:46

URL Encode, Decode function for MFC


Here's the good example for URL Encoding & Decoding.

inline BYTE toHex(const BYTE &x)
{
    return x > 9 ? x + 55: x + 48;
}

inline BYTE toByte(const BYTE &x)
{
    return x > 57? x - 55: x - 48;
}

CString URLDecode(CString sIn)
{
    CString sOut;
    const int nLen = sIn.GetLength() + 1;
    register LPBYTE pOutTmp = NULL;
    LPBYTE pOutBuf = NULL;
    register LPBYTE pInTmp = NULL;
    LPBYTE pInBuf =(LPBYTE)sIn.GetBuffer(nLen);
    //alloc out buffer
    pOutBuf = (LPBYTE)sOut.GetBuffer(nLen);
   
    if(pOutBuf)
    {
        pInTmp   = pInBuf;
        pOutTmp = pOutBuf;
        // do encoding
        while (*pInTmp)
        {
            if('%'==*pInTmp)
            {
                pInTmp++;
                *pOutTmp++ = (toByte(*pInTmp)%16<<4) + toByte(*(pInTmp+1))%16;
                pInTmp++;
            }
            else if('+'==*pInTmp)
                *pOutTmp++ = ' ';
            else
                *pOutTmp++ = *pInTmp;
            pInTmp++;
        }
        *pOutTmp = '\0';
        sOut.ReleaseBuffer();
    }
    sIn.ReleaseBuffer();
   
    return sOut;
}

CString URLEncode(CString sIn)
{
    CString sOut;
    const int nLen = sIn.GetLength() + 1;
    register LPBYTE pOutTmp = NULL;
    LPBYTE pOutBuf = NULL;
    register LPBYTE pInTmp = NULL;
    LPBYTE pInBuf =(LPBYTE)sIn.GetBuffer(nLen);
    //alloc out buffer
    pOutBuf = (LPBYTE)sOut.GetBuffer(nLen*3);
   
    if(pOutBuf)
    {
        pInTmp   = pInBuf;
        pOutTmp = pOutBuf;
        // do encoding
        while (*pInTmp)
        {
            if(isalnum(*pInTmp) || '-'==*pInTmp || '_'==*pInTmp || '.'==*pInTmp)
                *pOutTmp++ = *pInTmp;
            else if(isspace(*pInTmp))
                *pOutTmp++ = '+';
            else
            {
                *pOutTmp++ = '%';
                *pOutTmp++ = toHex(*pInTmp>>4);
                *pOutTmp++ = toHex(*pInTmp%16);
            }
            pInTmp++;
        }
        *pOutTmp = '\0';
        sOut.ReleaseBuffer();
    }
    sIn.ReleaseBuffer();
   
    return sOut;
}

Above sample code use CString, so if you want to use it on another type of development environment such as gcc or something like that, you need to add some more stuffs because it may not support CString class.
Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.

2007/10/11 11:48

Is there URLEncode function in Javascript ?


EncodeURI() is the answer.

and followings are the usage example:

<script type="text/javascript"><!--

  function MoveTab(txtObj, event)
  {
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 13) do_search();
  }

  function do_search()
  {
    if (document.getElementById("keyword").value)
    {
      self.location = "http://reportbank.com/s_" + EncodeURI(document.getElementById("keyword").value);
    }
  }
-->
</script>
<div width="100%" align=center>
  <font size=+6><strong>ReportBank</strong></font><br>
  <br>
    <input type=text id=keyword name=keyword size=20 value="<?=$keyword?>" onkeypress="return MoveTab(this, event)">
    <input type=button value=" Search " onclick="javascript:do_search()">
  <br>
</div>

Another posts included in "HTML, Javascript"

Two useful string functions - substr & substring (0)2008/01/15
Javascript based Regular Expression Tester (0)2008/01/15
Javascript based Browser Sniffing (0)2008/01/25
Move window (0)2007/09/07
How to calculate page loading time ? (0)2007/09/07
Number Of Vists (0)2007/09/07
Add Message On Mouse Traling (0)2007/09/07
Tooltip (0)2007/09/07
Trackback 10 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject Buy cheap xanax.

    Tracked from Xanax. 2009/03/12 12:14 delete

    Xanax dosage. Order xanax online. Xanax. Geniric xanax. No prescription xanax. Xanax 180 pills. Buy xanax online without a prescription.

  2. Subject Buy valium c.o.d..

    Tracked from Valium. 2009/06/17 07:09 delete

    Side effects of valium. Valium during pregnancy. Drug valium. Valium toxicity canine. Valium.

  3. Subject Valium.

    Tracked from No prescription generic valium. 2009/06/19 14:07 delete

    Valium without prescription. Roche valium for sale. Buy valium. Diazepam t quil valrelease valium data sheet. Valium dose appropriate. How long does valium stay. Valium.

  4. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 02:15 delete

    moneyideas

  5. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 10:58 delete

    moneyideas

  6. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:42 delete

    moneyideas

  7. Subject Cheap phentermine.

    Tracked from Phentermine lowest prices online cheap phentermine. 2010/02/09 00:14 delete

    Cheap phentermine. Catalog phentermine buy cheap phentermine online. Phentermine without an rx cheap prices. Cheap 37 5 phentermine. Buy cheap online phentermine. Phentermine cheap. Cheap phentermine diet pill.

  8. Subject Phentermine adipex.

    Tracked from Phentermine. 2010/05/13 21:46 delete

    Phentermine no prescription.

  9. Subject Cheapest phentermine online.

    Tracked from Phentermine online. 2010/05/17 22:20 delete

    Buy phentermine online. Lowes t online phentermine price. Purchasing discount phentermine online. Phentermine pill online d. Cheapest phentermine online. Buy phentermine order cheap online. Order phentermine phentermine online. Wrapper phentermine online.

  10. Subject Herbal phentermine.

    Tracked from Phentermine forum. 2010/05/31 19:18 delete

    Buy phentermine. Discount phentermine. Phentermine. Compare phentermine price.