Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

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?

Fazal Rehman Shamil Click Here to Know More
Instructor, Researcher, Blogger, SEO Expert, Poet and Publisher of International Journal Of Software, Technology & Science ISSN : 2616 - 5325
Dear Professors and Resarchers!You are welome to Cite these tutorials in your research or slides etc. Please don't forget to mention the reference of website. Copy Paste of text is strcitly forbidden. Images can be reuse because images are protected with watermark.