0

Help I am stuck with the following Problem and i cant figure this out. I am supposed to do the following in PHP:

Set a variable to the following: “<&¢£¥€©>” and output it as shown to the browser window.

Here is my code: <?php $str = "&lt;&amp;&cent;&pound;&yen;&euro;&copy;&gt;" echo htmlspecialchars($str); ?>

but i keep getting an error.

  • 1
    Why do you need to use htmlspecialchars when you already encode to HTML character already? – invisal Mar 05 '17 at 01:56
  • Read from here (multiple solution available) : http://stackoverflow.com/questions/17150403/how-should-i-echo-a-php-string-variable-that-contains-special-characters – Resheil Agarwal Mar 05 '17 at 01:58

2 Answers2

1

Missing semicolon

$str = "&lt;&amp;&cent;&pound;&yen;&euro;&copy;&gt;"; // <-- missing semicolon
echo htmlspecialchars($str);
Yolo
  • 1,569
  • 1
  • 11
  • 16
1

Do you mean you want to do something like this?

$str = "<&¢£¥€©>";
echo htmlspecialchars($str);
invisal
  • 11,075
  • 4
  • 33
  • 54