Return <andrebaill> result in browser

Asked

Viewed 25 times

1

I have the following answer:

<<?php echo $valor->usu_id; ?>>

However, it is interpreted by the browser as TAG and not as return. How do I make it return without being a tag? In this example, return <andrebaill>

1 answer

2


Use HTML entities like this:

&lt;<?php echo $valor->usu_id; ?>&gt;

A pure HTML example:

Vira tag: <br>

<foobar>

<hr>

É "visivel": <br>

&lt;foobar&gt;

List of HTML entities on W3.org: https://dev.w3.org/html5/html-author/charref

If the content comes from a variable in PHP (or bank) you can use htmlspecialchars thus:

<?php $foobar = '<foobar>'; ?>

<?php echo htmlspecialchars($foobar); ?>

Note:

The difference of htmlspecialchars and htmlentities is that the htmlspecialchars only encodes characters that have some meaning for HTML, whereas htmlentities encodes everything that has the equivalent in "HTML entities"


Note that there is a tag <xmp> which may have the same effect, however is obsolete (although it still works):

<xmp><foobar></xmp>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.