string - I want to convert alphabets to numbers, in this way: A=0, B=1, C=2... Z=25 using php -
i want write function take input string , convert alphabets number , returns converted numbers, in way: a(a)=1, b(b)=2, c(c)=3... z(z)=25 using php in advance
first, make lowercase.
then, using ord
function, ascii code, , substract 'a' it.
function one_char_map($chr) { $chr=strtolower($chr); return ord($chr)-ord('a'); } function string_map($str) { return implode(array_map('one_char_map',str_split($str))); } echo string_map('abcd');//0123
Comments
Post a Comment