-2

i would like to use the chr function to display abc++ in code block but i do not know how to incorporate the chr function in this block of html code.

       <?php 
      for ($x = 65 ; $x <= 90; $x ++){
      echo "<div class='black-box'>
        <div class='letter'>
        chr($x); <sub class='small'>$x</sub>
        </div>          
      </div>" ;} ?>  
Bogle
  • 69
  • 12

2 Answers2

0

What you could do is this: (Sorry no explaining, bad time)

<?php
    $x=0;
    $target = 5000;
    echo '<table style="width:50%;"><thead><tr><td style="width:50%;">Code</td><td style="width:50%;>Character</td></tr></thead><tbody>';
    while($x<$target){
        echo '<tr><td>'.$x.'</td><td>'.chr($x).'</td></tr>';
    }
    echo '</tbody></table>';
?>

EDIT

<?php
    $x = 65;
    $target = 90;
    function displaychar($from, $to){
        $string = "<table style='width:50%;'><thead><tr><td style='width:50%;'>Code</td><td style='width:50%;'>Character</td></tr></thead><tbody>";
        while($from<=$to){
            $string=$string. '<tr><td>'.$from.'</td><td>'.chr($from).'</td></tr>';
            $from++;
        }
        $string=$string. '</tbody></table';
        return $string;
    }
    echo displaychar($x, $target);
?>
  • thank you but this code did not work. i tried to use ' '.chr($x).' ' to display the chr function this did not work also – Bogle Oct 02 '16 at 23:29
0

You must concatenate the PHP function or echo it to make it work, so this is my code

<?php
for ($x = 65 ; $x <= 90; $x++) {
    echo "<div class='black-box'>
          <div class='letter'>";
    echo chr($x);
    echo "<sub class='small'>$x</sub>
          </div>
          </div>";
}
?>

EDIT
This next function, will output the same, but will be concatenated to the same echo:

<?php
for ($x = 65 ; $x <= 90; $x++) {
    echo "<div class='black-box'>
          <div class='letter'>".chr($x)."<sub class='small'>$x</sub>
          </div>
          </div>";
}
?>

Have a look here for more info: PHP Echo

matiaslauriti
  • 7,065
  • 4
  • 31
  • 43
  • 1
    worked thank you can you explain to me why you cancatenate – Bogle Oct 03 '16 at 02:32
  • @Bogle The problem in your question, from what I know and experience with PHP, is that you can't write a function inside `"` and think that PHP will use it. You must concatenate it to the text or echo. You could write all my 3 echoes in one echo, by writing `.` before each echo closure (`;`). Look at my answer to understand what I mean. – matiaslauriti Oct 03 '16 at 04:45