-1

Say, $var = "Hello<br>How are <strong>you</strong>";

I want echo $var to display the assigned string Hello<br>How are <strong>you</strong> as it is not the parsed html code.

How do I do that?

5
  • Do you want to strip the tags? Then use echo strip_tags($var);. Commented Aug 11, 2020 at 13:37
  • 2
    Ah, you want the HTML not parsed by the browser, then use echo htmlentities($var);. Commented Aug 11, 2020 at 13:38
  • 1
    Does this answer your question? Display HTML snippets in HTML Commented Aug 11, 2020 at 13:40
  • @MarkusZeller htmlentities answers the question.Thanks Commented Aug 11, 2020 at 15:38
  • Does this answer your question? Using htmlentities in a string Commented Aug 12, 2020 at 16:55

1 Answer 1

0

HTML tags will automatically parsed by the browser. To see the pure HTML source anyways, the tags needs to be encoded, especially the angle brackets.

There is a dedicated PHP function available for that called htmlentities().

$var = "Hello<br>How are <strong>you</strong>";
echo htmlentitites($var);

Will encode it in the browser so you can see it displayed as plain text like in $var. The browser will see this:

Hello&lt;br&gt;How are &lt;strong&gt;you&lt;/strong&gt;

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.