Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How easy convert Html encoded text to clear text?
Message
De
01/06/2010 09:10:25
 
 
À
01/06/2010 09:02:52
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01466814
Message ID:
01466823
Vues:
46
Courtesy Rick Strahl:
FUNCTION StripHTML
*******************
***  Function: Removes HTML tags from the passed text and converts
***            it to plain text. Note formatting is totally removed!
***    Assume: only <br> and <p> are translated
***            any < or > in the HTML besides tags will break this
***            function.
***      Pass: lcText  -   HTML Text to strip
***            lcLTag  -   Left Tag value ("<")
***            lcRTag  -   Right Tag Value (">")
***    Return: Stripped HTML text
*************************************************************************
LPARAMETER lcHTMLText, lcLTag, lcRTag

lcLTag=IIF(EMPTY(lcLTag),"<",lcLTag)
lcRTag=IIF(EMPTY(lcRTag),">",lcRTag)

IF ATC(lcLTag,lcHTMLText) = 0
   RETURN lcHTMLText
ENDIF

*** Start by breaking line breaks
lcHTMLText = STRTRAN(lcHTMLText,lcLTag + "BR" + lcRTag,CRLF)
lcHTMLText = STRTRAN(lcHTMLText,lcLTag + "P" + lcRTag,CRLF+CRLF)
lcHTMLText = STRTRAN(lcHTMLText,lcLTag + "br" + lcRTag,CRLF)
lcHTMLText = STRTRAN(lcHTMLText,lcLTag + "p" + lcRTag,CRLF+CRLF)
lcHTMLText = STRTRAN(lcHTMLText,"&nbsp;"," ")

lcExtract = "x"   
DO WHILE !EMPTY(lcExtract)
   lcExtract = Extract(lcHTMLText,lcLTag,lcRTag)

   IF EMPTY(lcExtract)
      EXIT
   ENDIF
   lcHTMLText = STRTRAN(lcHTMLText,lcLTag+lcExtract+lcRTag,"")
ENDDO

lcHTMLText = STRTRAN(lcHTMLText,"&lt;","<")
lcHTMLText = STRTRAN(lcHTMLText,"&gt;",">")

RETURN lcHTMLText
>Hi,
>Now this question about FoxPro :))
>
>Simple example
>
>
>
>lcText = FILETOSTR("somefile.xml")
>
>lcValue = STREXTRACT(lcText,"<Desc>","</Descr>")
>
>
>
>This lcValue has "& and another html encoded characters inside"
>
>I want to convert it to Text and save in Character field
>
>Denis
>
>>>Hi,
>>>I have a text in the XML node encoded with HTML & and so on..
>>>What is easy way to convert this value to clear text?
>>>
>>>Thanks
>>>Denis
>>
>>Can you post a sample of what do you mean? You can use value() method of XML, check, for example
>>http://bradsruminations.blogspot.com/2009/10/making-list-and-checking-it-twice.html
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform