2
20/10/2024 8:04 am
Topic starter
Write a function that receives two characters and prints on a single line all the characters in between them according to the ASCII table:
Examples:
1 Answer
2
20/10/2024 8:05 am
You can use those 2 PHP functions (explained in the comments in the code):
ord() - Click HERE to read about it
and
chr() - Click HERE to read about it
Also - there is swapping between variables between lines #13 and #17;
You can read how to swap 2 variables in PHP HERE
Here is the code:
<?php $first = readline(); $second = readline(); charsRange($first, $second); function charsRange($f, $s) { //ord() converts ascii value to its corresponding ascii number $start = ord($f); $end = ord($s); if ($end < $start) { $temp = $end; $end = $start; //start is bigger $start = $temp; //assigning value of the start } for ($i = $start + 1; $i < $end; $i++) { echo chr($i) . " ";//chr() converts ascii number to its corresponding ascii value } }