0

Is there a way to avoid the \ escape character in an echo? This works fine but is hard to read. What is the recommended way to handle this?

while($row = mysqli_fetch_array($result))
  {
  echo "<td><input id=\"EmpFirstName\" name=\"EmpFirstName\" type=\"text\" value=\"" . $row['EmpFirstName'] . "\"></td>";
  }
echo "</table>";
Rocco The Taco
  • 3,695
  • 13
  • 46
  • 79

1 Answers1

1

Use single-quotes for the HTML attributes:

while($row = mysqli_fetch_array($result)){
    echo "<td><input id='EmpFirstName' name='EmpFirstName' type='text' value='{$row['EmpFirstName']}'></td>";
}
echo "</table>";

It doesn't matter if you use single-quotes or double-quotes for HTML attributes. (See the Stack Overflow question Single vs Double quotes (' vs ") )

I also changed ".$row['EmpFirstName']." to {$row['EmpFirstName']}, which is slightly cleaner, and equally valid in PHP when using echo "";.

Community
  • 1
  • 1
Mooseman
  • 18,763
  • 14
  • 70
  • 93