Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urlencode - Urldecode 2

Status
Not open for further replies.

Prusso

Programmer
Jul 5, 2002
13
AR
Hi

Someone know of any funcion like the urlencode or urldecode of java or php for visual fox?

thanks a lot
 
I don't know of one, but with the following definition, it would seem to be fairly trivial to implement in VFP code.
"Returns a string in which all non-alphanumeric characters except -_, have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs." - PHP: Manual -
If someone hasn't written it, maybe I'll give it a try after the meeting I've got scheduled just about now.

Rick
 
I just happened to have this hanging around (converted from VB, who knows when or where from):
Code:
Function URLdecode
PARAMETER pcInStr
*  ' unencode EVERY %XX
*  ' (keep track of current position so you don't unencode
*  '  a percent that just came out of an URLencoded char
LOCAL I, tStr, tChr, tOut
  tStr = pcInStr
  tOut = ""
  tStr = StrTran(tStr, "+", " ")
  I = 1
  do While I <= Len(tStr)
    If (SubStr(tStr, I, 1) = &quot;%&quot;) ;
       And SubStr(tStr, I + 1, 1) $ &quot;0123456789ABCDEF&quot; ;
       And SubStr(tStr, I + 2, 1) $ &quot;0123456789ABCDEF&quot; 
      tChr = (( At( SubStr(tStr, I + 1, 1), &quot;0123456789ABCDEF&quot; )-1) * 16 ) ;
           + (( At( SubStr(tStr, I + 2, 1), &quot;0123456789ABCDEF&quot; )-1)      ) 
      I = I + 2
*03/18/03 Zero's are now allowed.      
      if between(tChr,0,255) && 03/18/03
*      if tChr > 0 and tChr < 255
        tOut = tOut + chr( tChr )
      endif
    else
      tOut = tOut + SubStr(tStr, I, 1)
    EndIf
    I = I + 1
  EndDo
RETURN tOut

**********************************************************
Function URLencode
PARAMETER pcInStr
*  ' encode Percent signs
*  '        Double Quotes
*  '        CarriageReturn / LineFeeds
LOCAL lcOut, lnI
  lcOut = ''
  for lnI = 1 to len(pcInStr)
    lcCh = Substr(pcInStr,lnI,1)
    if not between( lcCh, chr(33), chr(126) ) ;
       or inlist(lcCh,[+],[%],[&quot;],[,],['],[`],[=],[ ],[&])
      lcCh = '%' + PADL( int2Hex( asc(lcCh) ), 2, '0' )
    endif
    lcOut = lcOut + lcCh
  endfor
*!*	  lcOut = pcInStr
*!*	  lcOut = StrTran(lcOut, &quot;+&quot;,  &quot;%2B&quot;)
*!*	  lcOut = StrTran(lcOut, &quot;%&quot;,  &quot;%25&quot;)
*!*	  lcOut = StrTran(lcOut, '&quot;',  &quot;%22&quot;)
*!*	  lcOut = StrTran(lcOut, &quot;,&quot;,  &quot;%2C&quot;)
*!*	  lcOut = StrTran(lcOut, Chr(13) + Chr(10), &quot;%0D%0A&quot; )
*!*	  lcOut = StrTran(lcOut, Chr(13), &quot;%0D&quot;)
*!*	  lcOut = StrTran(lcOut, Chr(13), &quot;%0A&quot;)
RETURN lcOut
 
Ok, I remembered where this code came from: It's converted from VB code I had written originally....

Also, you'll need to replace the line:
lcCh = '%' + PADL( int2Hex( asc(lcCh) ), 2, '0' )

with this:
lcCh = '%' + RIGHT( tran(asc(lcCh),'@0'), 2 )

(unless you happen to have a function Int2Hex that works exactly like mine.... tran() should be faster, anyway)
 
Thanks to all of you, special for wgcs

Pablo from Argentina
 
Thanks, ooritz, I didn't know those API calls existed!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top