ASCII Values program in PHP
1 2 3 4 5 6 7 |
<?php $str = "t"; for ( $pos=0; $pos < strlen($str); $pos ++ ) { $byte = substr($str, $pos); echo $str.' has value ' . ord($byte).PHP_EOL; } ?> |
Output
t has value 116
How to show ASCII Values in PHP with the form?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form method="POST"> Enter Character: <input type="text" name="1"><br> <input type="submit"value="Print ASCII" name="submit"> </form> <?php if (isset($_POST['submit'])){ $str = $_POST['1'];; for ( $pos=0; $pos < strlen($str); $pos ++ ) { $byte = substr($str, $pos); echo $str.' has value ' . ord($byte).PHP_EOL; }} ?> </body> </html> |
Output

Topic Covered
How to show ASCII Values in PHP?