Using the htmlentities() function

Strings with single quotes

An example that doesn’t use the htmlentities() function

<?php
  $copyright1 = "\xa9 2022";                // Result is '© 2022'
  echo $copyright1;                         // Some browsers display � 2022
?>

An example that uses the htmlentities() function

<?php
  $copyright2 = htmlentities("\xa9 2022");  // Result is '© 2022'
  echo $copyright2;                         // Browsers display © 2022
?>

Back