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; } Link to comment https://forums.phpfreaks.com/topic/105274-js-php/ 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... Link to comment https://forums.phpfreaks.com/topic/105274-js-php/#findComment-539140 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; } Link to comment https://forums.phpfreaks.com/topic/105274-js-php/#findComment-539241 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.