Encode a string into character codes
character, php, string
Solution
function encode_everything($string){
$encoded = "";
for ($n=0;$n<strlen($string);$n++){
$check = htmlentities($string[$n],ENT_QUOTES);
$string[$n] == $check ? $encoded .= "&#".ord($string[$n]).";" : $encoded .= $check;
}
return $encoded;
}
Found at:
http://php.net/manual/en/function.htmlentities.php
Problem
I want to encode an email address into its corresponding character codes, so when it is printed the char codes are interpreted by the browser, but the robots get the encoded string instead of the interpreted one. For example (1): ``` abc@abc.com ``` should be sent to the browser as (2) (whitespaces added so the browser shows it): ``` a ;b ;c ;@ ;a ;b ;c ;. ;c ;o ;m ; ``` so the human reads (1) and web robots read(2) There should be an easy function or way to do this, but cannot find one.