crashmaster Posted May 12, 2008 Share Posted May 12, 2008 Can anyone translate this in PHP ?? function toEntity() { var aa = document.form.utf.value; var bb = ''; for(i=0; i<aa.length; i++) { if(aa.charCodeAt(i)>127) { bb += '&#' + aa.charCodeAt(i) + ';'; } else { bb += aa.charAt(i); } } document.form.entity.value = bb; } Quote Link to comment Share on other sites More sharing options...
rarebit Posted May 12, 2008 Share Posted May 12, 2008 function toEntity($aa) { $bb = ''; for($i=0; $i<strlen($aa); $i++) { if(ord($aa[$i])>127) { $bb .= ''.ord($aa[$i]).';'; } else { $bb .= $aa[$i]; } } return $bb; } I've not tested it but it looks about right... Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 12, 2008 Share Posted May 12, 2008 Just because I like compact code: function toEntity($aa) { $bb = ''; for($i=0; $i<strlen($aa); $i++) { $bb .= (ord($aa[$i])>127)? ''.ord($aa[$i]).';' : $aa[$i] ; } return $bb; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.