dongnao2048 2014-01-23 17:33
浏览 50
已采纳

php echo html标签所以它是可见的(不解释为代码)

I am currently trying to echo a text value from a variable which contains html-style tags. <...>

$string = "variable_name";
$tag_str = "<".$string.">";
echo $tag_str;

currently this echo's as nothing as it believes it is html code. How would I go about echoing <variable_name> to the page so it is viewable and not interpreted as code by the browser?

  • 写回答

3条回答 默认 最新

  • dongyan3562 2014-01-23 17:35
    关注

    You'll have to html encode your output

    $string = "variable_name";
    $tag_str = "<".$string.">";
    echo htmlspecialchars($tag_str);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?