javascript - why CRLF transformed to LF when they are assigned to using php -
javascript - why CRLF transformed to LF when they are assigned to <input> using php -
(1)a form include textarea,type text line break it.like :
a b
then submit form , store text database.the length of contents 4.i can output ascii codes,using ord() function.they 97(a), 13(cr), 10(lf), 98(b).
(2)get contents , assign them template using smarty.like:
//$string database. $smarty->assign('str', $string);
using input element store contents in html template.
<input id="test" type="hidden" value="{$str}">
(3)get length of input value
document.getelementbyid("test").value.length; //the result 3
while using
{$str|@strlen} //the result 4
if submit form , ascii code of cotents,they 97(a), 10(lf), 98(b). character 13(cr) lost.
i googled lot didn't find reason. explanation? lot in advance.
i found :
https://bugzilla.mozilla.org/show_bug.cgi?id=188015
someone replied in comment 28 , official docs transferred to:
http://www.w3.org/tr/html5/syntax.html#preprocessing-the-input-stream
"cr" (u+000d) characters , "lf" (u+000a) characters treated specially. cr characters must converted lf characters, , lf characters follow cr character must ignored.
hope help.
what happens html get's rendered (i've escaped cr character:)
<input id="test" type="hidden" value="a\13 b">
and browser trims whitespace, deleting cr character.
what can render urlencode($str) instead of plain $str variable. way browser won't mess command characters. you'll have urldecode on other side, though.
javascript php html dom
Comments
Post a Comment