Posted By

luizlopes on 11/20/08


Tagged

String ascii convert for ord strlen


Versions (?)

Convert string to ASCII Value


 / Published in: PHP
 

URL: http://twitter.com/jfanaian/statuses/1015463286

My friend Jamal Fanaian showed me how to convert a string to its' ASCII value.

  1. function string_to_ascii($string)
  2. {
  3. $ascii = NULL;
  4.  
  5. for ($i = 0; $i < strlen($string); $i++)
  6. {
  7. $ascii += ord($string[$i]);
  8. }
  9.  
  10. return($ascii);
  11. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: kirkstrobeck on February 10, 2009

That was helpful, but this is what I did and what I needed. Simple email confuser, not much, but helps a bit -- 37Signals uses this method

function strtoentity($input) { foreach (str_split($input) as $obj) { $output .= '&#' . ord($obj) . ';'; } return $output; }

Posted By: kirkstrobeck on February 10, 2009
function strtoentity($input)
{ 
    foreach (str_split($input) as $obj) 
    { 
        $output .= '&#' . ord($obj) . ';'; 
    }
    return $output;
}

You need to login to post a comment.