How to Convert a String to a Decimal in PHP

104 15
    • 1). Decide how you will run your PHP code. If you have a PHP server, you can execute code using PHP files. Otherwise, use an online PHP interpreter. Enter the code in this tutorial into either a PHP file or the interpreter.

    • 2). Begin your PHP program with the following statement:

      <?php

    • 3). Declare a character string by writing the following line of code in a new line below the previous statement:

      $character = 'a';

    • 4). Convert the character string into its ASCII decimal value using the ord function. This function returns a new value that must be stored in a new variable. To store the returned value, you can create a new variable named $newCharacter and call the function like this:

      $newCharacter = ord($character);

    • 5). Print the ASCII decimal value using the print function, like this:

      print($newCharacter)

    • 6). Conclude your PHP program with the following statement. Your program is now ready to be tested on your server or interpreter.

      ?>

    • 7). Run the program. The output is the ASCII decimal value for the letter a, and it looks like this:

      226

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.