简体   繁体   中英

PHP won't echo “<” symbol from database

I'm trying learn PHP + mysql and when saved data to my database PHP wont echo lines that start with "<" symbol

mysql at screenshot, code under

  $result2 = mysqli_query($con, "SELECT * FROM ta_pastat pastat left join ta_users tusers on pastat.kirjoittaja_ID = tusers.ID where pastat.kategoria_ID = 1");
while($row2 = mysqli_fetch_array($result2)){
//$row2 = preg_match('(^|>)(&gt;[^<]*)', "\\1<div class=\"unkfunc\">\\2</div>", $row2);

$style = "";
switch( substr($row2['Teksti'], 0, 1) ) {
    case ">":
        $style = "style=\"color:#789922\"";
        break;
    case "<":
        $style = "style=\"color:#226199\"";
        break;
}
//echo nl2br("<h4 $style>".$row2['Teksti']."</h4><br>".PHP_EOL);
echo nl2br("<br><h1>".$row2['Otsikko']."</h1><br><h4 $style>".$row2['Teksti']."</h4><hr>");

由于浏览器会将其解释为HTML,因此您需要将其包装在htmlentities

echo nl2br("<br><h1>".$row2['Otsikko']."</h1><br><h4 $style>".htmlentities($row2['Teksti'])."</h4><hr>");

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