FoxPro Programming
Re: Convert HTML to standard ASCII characters
09/05/2010
08:18:29 AM
30U0HT3TA Show this entire thread in new window
Gratar Image based on email address
From:
Harvey Mushman
To:
Rick Strahl 
Attachments:
None
Is there any reason that I should be aware of why this function is no longer supported in the documentation?

I am finding a lot of HTML encoded characters get injected into user text when because I an using the FCK Editor for data entry. Now that I want to produce reports using the report writer, things like accent marks and paragraph breaks look really crapy in my PDF output.

Although using ALLTRIM( StripHTML( myMemoField ),1,chr(13),chr(10)) sort of works, it still leaves me with encoded ndash, rsquo and ccedil to name a few.

...back to the drawing board!<g>

--hm


wwUtils includes HtmlDecode() which does Html entity decoding:

************************************************************************ * wwUtils :: HtmlDecode **************************************** *** Function: *** Assume: *** Pass: *** Return: ************************************************************************ FUNCTION HtmlDecode(lcText) lcRetval = "" DO WHILE .T. *** Format: �A; ( CHR(10) ) lnLoc = AT('&#',lcText) *** No Hex chars - just return the text IF lnLoc > LEN(lcText) - 2 OR lnLoc < 1 lcRetval = lcRetval + lcText EXIT ENDIF *** Now read the next 2 characters *** Check for digits - at this point we must have hex pair! lcHex=SUBSTR(lcText,lnLoc+2,2) *** Now concat the string plus the evaled hex code lcRetval = lcRetval + LEFT(lcText,lnLoc-1) + ; CHR( EVAL(lcHex) ) *** Trim out the input string IF LEN(lcText) > lnLoc + 2 lcText = SUBSTR(lcText,lnLoc+5) ELSE EXIT ENDIF ENDDO RETURN lcRetVal ENDFUNC * wwUtils :: HtmlDecode

You may have to modify this to work with 4 digit unicode entities.

+++ Rick ---


How do I convert special characterds from HTML to standard ASCII characters?

For example:

"Yôko Mihara" ==> "Yôko Mihara"

in this case the "ô" is represented as "& # x F 4 ;" in HTML (without spaces)

I tried STRCONV() but it did not help. I havea feelign this should be vrey simple

Please help!