PHP String Encoder (for Javascript Alert, Confirm, etc.)


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function jsStrEncode($s, $r=true, $p="\\") {
  2. $c = array("¢"=>$p."242", "£"=>$p."243", "€"=>$p."244", "¥"=>$p."245", "°"=>$p."260", "¼"=>$p."274", "½"=>$p."275", "¾"=>$p."276", "¡"=>$p."241", "«"=>$p."253", "»"=>$p."273", "¿"=>$p."277", "À"=>$p."300", "Á"=>$p."301", "Â"=>$p."302", "Ã"=>$p."303", "Ä"=>$p."304", "Å"=>$p."305", "Æ"=>$p."306", "Ç"=>$p."307", "È"=>$p."310", "É"=>$p."311", "Ê"=>$p."312", "Ë"=>$p."313", "Ì"=>$p."314", "Í"=>$p."315", "Î"=>$p."316", "Ï"=>$p."317", "Ð"=>$p."320", "Ñ"=>$p."321", "Ò"=>$p."322", "Ó"=>$p."323", "Ô"=>$p."324", "Õ"=>$p."325", "Ö"=>$p."326", "Ø"=>$p."330", "Ù"=>$p."331", "Ú"=>$p."332", "Û"=>$p."333", "Ü"=>$p."334", "Ý"=>$p."335", "Þ"=>$p."336", "ß"=>$p."337", "à"=>$p."340", "á"=>$p."341", "â"=>$p."342", "ã"=>$p."343", "ä"=>$p."344", "å"=>$p."345", "æ"=>$p."346", "ç"=>$p."347", "è"=>$p."350", "é"=>$p."351", "ê"=>$p."352", "ë"=>$p."353", "ì"=>$p."354", "í"=>$p."355", "î"=>$p."356", "ï"=>$p."357", "ð"=>$p."360", "ñ"=>$p."361", "ò"=>$p."362", "ó"=>$p."363", "ô"=>$p."364", "õ"=>$p."365", "ö"=>$p."366", "ø"=>$p."370", "ù"=>$p."371", "ú"=>$p."372", "û"=>$p."373", "ü"=>$p."374", "ý"=>$p."375", "þ"=>$p."376", "ÿ"=>$p."377");
  3. $x = strtr($s,$c);
  4. if ($r){
  5. return($x);
  6. } else {
  7. print($x);
  8. }
  9. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.