DATA Methods
Database functions
select(), fetch(), write(), update(), delete(), execute(), tables(), fields()Requests and temporary storage
request(), cookie(), session(), config(), store()Formatting data
encode(), decode(), json(), text(), date(), weekday(), month()Template data
content(), parents(), directory()
encode()
Encodes text in various ways. Use decode() to reverse encoding.
string encode( string text [, int type = 1 ])
Return
Encoded text.
Parameter
Description
textThe text to be encoded.
type0 = no encoding
1 = html-entities QUOTES
2 = html-entities NOQUOTES
3 = url-encode
4 = json-encode
5 = javascript encode
Javascript-encoding will escape quotes and double-qoutes as well as remove any linefeeds or carriage returns. This way you can use the encoded value inside a javascript variable. Make sure to use your JS quotes adequately.
1 = html-entities QUOTES
2 = html-entities NOQUOTES
3 = url-encode
4 = json-encode
5 = javascript encode
Javascript-encoding will escape quotes and double-qoutes as well as remove any linefeeds or carriage returns. This way you can use the encoded value inside a javascript variable. Make sure to use your JS quotes adequately.
Encode entities
$DATA->encode("<script>alert('test')</script>")
RETURN: '<script>alert('test')</script>'
Encode entities but no quotes
$DATA->encode("<script>alert('test')</script>", 2)
RETURN: '<script>alert('test')</script>'
URL encode
$DATA->encode("<script>alert('test')</script>", 3)
RETURN: '%3Cscript%3Ealert%28%27test%27%29%3C%2Fscript%3E'
JSON encode
$DATA->encode("alert('test1');" .'alert("test2");', 4)
RETURN: '"alert('test1');alert(\"test2\");"'
Javascript Encode
'<p class="test">' .$DATA->encode('This "code" can go into a ' ."\n" ."into a 'js variable' !!", 5). '</p>'
RETURN: '<p class="test">This "code" can go into a into a <js variable< !!</p>'