简体   繁体   中英

HTML being displayed as text

When I load the following code using php...

<?php <h1>Some text</h1>?>

the tags are printed as text -

<h1>Some text</h1>

Any ideas?

Found the answer - see my answer.

You need to output the actual HTML code if you are placing any HTML code within PHP.

You can achieve this using echo() .

<?php
    echo("<h1>Some text</h1>");
?>
<h1><?php Some text ?></h1>

why dont you try this.

You must print it in order for it to appear the way you want it to

<?php echo"<h1>Some text</h1>" ?>

like this

Found the issue, the content-type was set as json.

<?php echo "<h1>Some text</h1>"; ?>
<?php echo "<h1>Some text</h1>"; ?>

if you want to show a variable

<?php
$_varTest=2;
echo "<h1>Show variable {$_varTest}</h1>"; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM