$string="Let us print a variable ".chr(36)."my_var";
Output ( char(36) is $ )
Let us print a variable $my_var
Same way we can change the string and check the outputs
echo "Let us print hash ".chr(35); //Output Let us print hash #
echo " Less than ".chr(60); // Output Less than <
We can use ord function to get ASCII value of any character<?Php
$i=0;
echo "<table><tr><td>";
for($i==0;$i<=127;$i++){
echo " chr($i) = ".chr($i)."<br>";
if($i%20 == 0 and $i>19){echo "</td><td valign=top>";}
}
echo "</td></table>";
?>
The output of this is here
chr(0) = | ||||
chr(1) = | chr(2) = | chr(3) = | chr(4) = | chr(5) = |
chr(6) = | chr(7) = | chr(8) = | chr(9) = | chr(10) = |
chr(11) = | chr(12) = | chr(13) = | chr(14) = | chr(15) = |
chr(16) = | chr(17) = | chr(18) = | chr(19) = | chr(20) = |
chr(21) = | chr(22) = | chr(23) = | chr(24) = | chr(25) = |
chr(26) = | chr(27) = | chr(28) = | chr(29) = | chr(30) = |
chr(31) = | chr(32) = | chr(33) = ! | chr(34) = " | chr(35) = # |
chr(36) = $ | chr(37) = % | chr(38) = & | chr(39) = ' | chr(40) = ( |
chr(41) = ) | chr(42) = * | chr(43) = + | chr(44) = , | chr(45) = - |
chr(46) = . | chr(47) = / | chr(48) = 0 | chr(49) = 1 | chr(50) = 2 |
chr(51) = 3 | chr(52) = 4 | chr(53) = 5 | chr(54) = 6 | chr(55) = 7 |
chr(56) = 8 | chr(57) = 9 | chr(58) = : | chr(59) = ; | chr(60) = < |
chr(61) = = | chr(62) = > | chr(63) = ? | chr(64) = @ | chr(65) = A |
chr(66) = B | chr(67) = C | chr(68) = D | chr(69) = E | chr(70) = F |
chr(71) = G | chr(72) = H | chr(73) = I | chr(74) = J | chr(75) = K |
chr(76) = L | chr(77) = M | chr(78) = N | chr(79) = O | chr(80) = P |
chr(81) = Q | chr(82) = R | chr(83) = S | chr(84) = T | chr(85) = U |
chr(86) = V | chr(87) = W | chr(88) = X | chr(89) = Y | chr(90) = Z |
chr(91) = [ | chr(92) = \ | chr(93) = ] | chr(94) = ^ | chr(95) = _ |
chr(96) = ` | chr(97) = a | chr(98) = b | chr(99) = c | chr(100) = d |
chr(101) = e | chr(102) = f | chr(103) = g | chr(104) = h | chr(105) = i |
chr(106) = j | chr(107) = k | chr(108) = l | chr(109) = m | chr(110) = n |
chr(111) = o | chr(112) = p | chr(113) = q | chr(114) = r | chr(115) = s |
chr(116) = t | chr(117) = u | chr(118) = v | chr(119) = w | chr(120) = x |
chr(121) = y | chr(122) = z | chr(123) = { | chr(124) = | | chr(125) = } |
chr(126) = ~ | chr(127) = |
We can use *chr()* to create special HTML characters, such as © or ®, dynamically using their ASCII values:
echo "Copyright: " . chr(169) . " 2024"; // Outputs: Copyright: © 2024
We can create a range of characters using a loop:
for ($i = 65; $i <= 90; $i++) {
echo chr($i) . " "; // Outputs A to Z
}