Question #6179   Submitted by Answiki on 05/22/2022 at 03:41:06 PM UTC

How to escape HTML tags from a string in PHP?

Answer   Submitted by Answiki on 05/22/2022 at 03:42:06 PM UTC

The PHP function htmlspecialchars() is dedicated to escape or convert special characters in string to HTML entities . the function replaces the following characters:

  • ampersand ( & ) => &amps;
  • double quotation mark ( " ) => "
  • single quotation mark ( ' ) => ' ou '
  • the sign less than ( < ) => &lt;
  • the sign greater than ( > ) => &gt;


For example:

$string = '<a href="https://ans.wiki">Answiki</a>';
$string = htmlspecialchars($string);

// Affiche : <a href="https://ans.wiki">Answiki</a>
echo $string;


See also:

4 events in history
Answer by Answiki on 05/22/2022 at 03:42:06 PM

The PHP function htmlspecialchars() is dedicated to escape or convert special characters in string to HTML entities . the function replaces the following characters:

  • ampersand ( & ) => &amps;
  • double quotation mark ( " ) => &quot;
  • single quotation mark ( ' ) => &#039; ou &apos;
  • the sign less than ( < ) => &lt;
  • the sign greater than ( > ) => &gt;


For example:

$string = '<a href="https://ans.wiki">Answiki</a>';
$string = htmlspecialchars($string);

// Affiche : <a href="https://ans.wiki">Answiki</a>
echo $string;


See also:

Answer by Answiki on 05/22/2022 at 03:42:00 PM

The PHP function htmlspecialchars() is dedicated to escape or convert special characters in string to HTML entities . the function replaces the following characters:

  • ampersand ( & ) => &amps;
  • double quotation mark ( " ) => &quot;
  • single quotation mark ( ' ) => &#039; ou &apos;
  • the sign less than ( < ) => &lt;
  • the sign greater than ( > ) => &gt;


For example:

$string = '<a href="https://ans.wiki">Answiki</a>';
$string = htmlspecialchars($string);

// Affiche : <a href="https://ans.wiki">Answiki</a>
echo $string;


See also:

Question by Answiki 05/22/2022 at 03:41:06 PM
How to escape HTML tags from a string in PHP?
Question by Answiki 05/22/2022 at 03:29:18 PM
How does the PHP function htmlspecialchars() work?
# ID Query URL Count

Icons proudly provided by Friconix.