Tech Tip: Encoding HTML characters
PRODUCT: 4D | VERSION: 13.0 | PLATFORM: Mac & Win
Published On: April 13, 2012
This is a helper function to convert a string with HTML characters to their HTML Character Equivalents
// ---------------------------------------------------- // Method: HTML Convert // Description // This method will convert a string to the HTML // character equivalents // // Parameters // ---------------------------------------------------- C_TEXT($0;$1) C_TEXT($input;$convert) $input:=$1 $convert:="<!--#4DTEXT $input-->" PROCESS 4D TAGS($convert;$0) |
For example this block of code
C_TEXT($test;$result) $test:="A 'quote' is <b>bold</b>" $result:=HTML Convert ($test) |
Will have $result equal to: A &#39;quote&#39; is &lt;b&gt;bold&lt;/b&gt;
This can also be accomplished using the PHP command htmlentities()
C_TEXT($0;$1) C_TEXT($input;$output) C_INTEGER($flag) $input:=$1 $isOk:=PHP Execute("";"constant";$flag;"ENT_QUOTES") If ($isOk) $isOk:=PHP Execute("";"htmlentities";$output;$input;$flag) End if $0:=$output |
The PHP command htmlentities() has flags that modify the behavior of the function. Learn more here: http://php.net/manual/en/function.htmlentities.php
Commented by Dave M. Porter on December 10, 2013 at 8:35 AM
Replace $input in method: HTML Convert , with a process variable.Otherwise, when compiled this error is generated