On Jan 10, 2007, at 7:42 AM, Brad Perkins wrote:

Norbert Pfaff wrote:
Hi,

I have to display text, which my users enter in a form. In the form everything is fine, in the database the text is fine, if I display the text later the text is without structure. No more line feeds, carriage return etc.



Any tipps?
Norbert,

That is standard behavior. If you need line breaks in HTML you need to insert a <br />.
I have a simple method called nl2br which I use like this.

write (nl2br($someStructuredText))

nl2br simply replaces carriage returns in the output text with "<br />";

   method "nl2br" ($inTxt)
   `
` Converts any instances of carriage return, carriage return/ line feed,
   `   or line feed characters to the HTML break entity
   `
   `
         $cr   := char(13)
       $lf   := char(10)
       $crlf := $cr + $lf
       $br   := "<br />"
             $outTxt := $inTxt
             if (position($crlf;$outTxt)>0) `CRLFs?
           $outTxt:=replace string($outTxt;$crlf;$br)
       end if
             if (position($lf;$outTxt)>0) `LFs?
           $outTxt:=replace string($outTxt;$lf;$br)
       end if
             if (position($cr;$outTxt)>0) `CRs?
           $outTxt:=replace string($outTxt;$cr;$br)
       end if
             return ($outTxt)
         end method `"nl2br

I've used this method for some time. This functionality might be built into a standard A4D command now?

-- Brad

I have taken a slightly different approach from Brads. Mine also attempts to protect against code injection into the html while allowing users to do some really basic formating:

C_TEXT($TextIn)  `Text to convert
C_TEXT($TextOut) `Converted Text

`first, change any "<" or ">" to html entities so that we conrol the content
$t_ConvertedText:=Replace string($t_ConvertedText;"<";"&lt;")
$t_ConvertedText:=Replace string($t_ConvertedText;">";"&gt;")

  `we'll allow some real simple html
$t_ConvertedText:=Replace string($t_ConvertedText;"&lt;b&gt;";"<b>") `bold $t_ConvertedText:=Replace string($t_ConvertedText;"&lt;/b&gt;";"</ b>") `end bold $t_ConvertedText:=Replace string($t_ConvertedText;"&lt;i&gt;";"<i>") `Italic $t_ConvertedText:=Replace string($t_ConvertedText;"&lt;/i&gt;";"</ i>") `end Italic

  `convert carriage returns to <br> for html display
$t_ConvertedText:=Replace string($t_ConvertedText;Char(Carriage return )+Char(Line feed );"<br />") $t_ConvertedText:=Replace string($t_ConvertedText;Char(Carriage return );"<br />") $t_ConvertedText:=Replace string($t_ConvertedText;Char(Line feed );"<br />")

Return ($TextOut)


Bill Leddy


_______________________________________________
Active4D-dev mailing list
[email protected]
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/

Reply via email to