print the contents of PHP variable as text string in HTML

后端 未结 5 1961
旧时难觅i
旧时难觅i 2021-01-21 21:23

in a wordpress php script, I have the following:

echo \'
\' . $slide_media . \'
\' . \
5条回答
  •  余生分开走
    2021-01-21 21:41

    If you're outputting raw HTML to a HTML document (and you want it shown as text instead of text), you can use htmlentities($string):

    htmlentities($slide_media);
    

    If your string is UTF8, you might have to specify this (if your PHP version is 5.4+, you don't have to specify UTF-8, as it's default):

    htmlentities($slide_media, ENT_QUOTES, "UTF-8");
    

    You can also strip all HTML tags from the variable by using strip_tags($string):

    strip_tags($slide_media);
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题