Reputation: 192
The google books api returns a volumeid for each book. This volumeid is string like this
AZ5J6B1-4BoC
UvK1Slvkz3MC
OBM3AAAAIAAJ
So there are capital letters , small letters, characters like dash(-) underscore(_) etc
So is there a library that converts these characters to integer?
Also can I just convert the string to certain number like
[A-Z]=[0-25]
[a-z]=[26-50]
[special characters like -,_,]=[51-...]
Will the above self-cooked script good or are there certain standard functions in php that do the job?
Upvotes: 2
Views: 2518
Reputation: 1839
Simple use http://www.php.net/manual/en/function.ord.php
function num($text)
{
$num=null;
for ($i = 0; $i < strlen($text); $i++)
{
$num =$num.ord($text[$i]);
}
return($num);
}
Example 10183491225753109122105505667. It is 30 digit long number but if you want a unique number then this is it.
Upvotes: 5
Reputation: 3698
For this there is no standard function for this. We have write customize code for this.
<?php
function AsciiToInt($char){
$success = "";
if(strlen($char) == 1)
return "char(".ord($char).")";
else{
for($i = 0; $i < strlen($char); $i++){
if($i == strlen($char) - 1)
$success = $success.ord($char[$i]);
else
$success = $success.ord($char[$i]).",";
}
return "char(".$success.")";
}
}
echo AsciiToInt("<br>");//outputs char(60,98,114,62)
?>
Upvotes: 1