How to show ASCII Values in PHP?

ASCII Values program in PHP

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

<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

How to show ASCII Values in PHP
Figure: How to show ASCII Values in PHP

Topic Covered

How to show ASCII Values in PHP?

Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.