2

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?

1

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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)
    ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.