forms - how to convert altcodes to html code in php -
i'm working on website have form, if enter text works should if enter special characters ☺ ☻ ♥ ♦
becomes lot of ??
in database. there way convert them html code?
example: ♥
convention served ♥
the function looking htmlentities
http://php.net/manual/en/function.htmlentities.php
you'll need know encoding input data uses (obviously). default utf8.
$encoded = htmlentities( $input, ent_compat | ent_html401, 'utf-8', false );
note i've set final parameter false
(default true
). users can type, example, &
, convert &
. maybe want default behaviour (&
-> &
)
the encoding used when sending post data can set in form
tag:
<form method="post" action="myscript.php" accept-charset="utf-8">
but see here discussion: is there benefit adding accept-charset="utf-8" html forms, if page in utf-8?
Comments
Post a Comment