Daily Archives: 2011-12-22


Javascript Function: strToPhpChr(str)

There are times when converting a string into PHP concatenated chr( ) functions are very useful.
So, here is a simple javascript function, who do the dirty job.

/**
* @author Petros Kyladitis - 2011
* @license MIT License
* @description get PHP concatenated chr( ) functions from a string
* @param str String to be converted
* @return the PHP code
*/
function strToPhpChr(str){
  var strLen = str.length ;
  var phpCharCode = '' ;
  for(i=0; i<strLen; i++){
    phpCharCode +=  'chr(' + str.charCodeAt(i) +  ').' ; 
  } 
  return phpCharCode.substring(0, phpCharCode.length-1) ; 
}