html - Replace non standard characters in php -
i'm trying replace non standard characters ë,Ë,ç,Ç numeric entities Ë
, '
etc ran bit of problem.
when try replace them directly works fine:
$string = "Ë"; $vname = str_replace("Ë","aaaa",$string); echo $vname."<br>";
an aaaa result. when try replace characters string form post doesn't change characters. here example:
<?php if(isset($_post['submit'])) { $string = $_post['title']; if ($string == "Ë") echo "yes"; else echo "no"; $vname = str_replace("Ë","aaaa",$string); echo $vname."<br>"; echo $string; } ?> <form method="post" name="form"> title: <input name="title" type="text" value="" size="20"/> <input name="submit" type="submit" value="submit"/> </form>
any great!!
most characterset wrong. suggest sending following header when outputing html:
<?php header("content-type: text/html; charset=utf-8"); ?>
where charset match charset storing file in.
edit: more information. file store in 1 charset example latin1, while browser interprets html page charset (utf-8 example). when browser sends Ë character, send utf-8 code 0xc38b, while same character 0xcb. can see, these not match.
edit - can update charset via html5 or xhtml:
html5
<meta charset="utf-8"/>
xhtml
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
Comments
Post a Comment