Echo a variable to only display content, not rendered HTML

I have a variable

$a = "any<br>title";

when I echo it, Im trying to get it to display in 1 line (any<br>title)
and not like
any
title
Is there a function that does this?

I don’t understand what you are asking.
Can you explain it better?

Having the <br> will add a line break when you view in the browser, but not in the source.

What it the result you want?

My bad, so I have a variable with a <br> in it.

The result im looking for is when I echo it, instead of it displaying as two separate lines (the <br> is the line break)
I want it to display as 1 line (the <br> isn’t seen by the browser as a line break, but rather part of the variable)

So you want to actually see <br> in the browser?

If so then you need to encode the characters. Use htmlspecialchars to do that, it will turn < to &lt; in the source, but but the browser displays it as <.

1 Like

Alternatively you could just write it as &lt;br&gt; in the first place. But the function automates the process where there is a lot of code or where you don’t have control over the source string, such as user input (which is often where it’s used to reduce the risk of script injection).

Try this:

https://www.php.net/manual/en/function.strip-tags.php

Does the variable have the <br> in it, or does the value have the <br> in it?

$a = "any<br>title";

It looks like you are talking about the value of the variable, which can change as needed of course.

We DO ask for “working pages” or “working examples” so we can see what you see and the code that you are using. (Avoids a lot of guessing on our part. Permits accurate replies.) See our posing guidelines if you’ve forgotten.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.