print the contents of PHP variable as text string in HTML

后端 未结 5 1955
旧时难觅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 <b>text</b> 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);
    
    0 讨论(0)
  • 2021-01-21 21:54
    <?php print_r($slide_media); ?> 
    

    should do the trick for you.

    0 讨论(0)
  • 2021-01-21 22:00

    To see what is within a variable (maybe it is in array, an object or something else) use print_r($slide_media); or var_dump($slide_media);

    0 讨论(0)
  • 2021-01-21 22:03

    print_r Prints human-readable information about a variable

    0 讨论(0)
  • 2021-01-21 22:05

    I would do:

    echo '<pre>' . var_export($slide_media, true) . '</pre>';
    

    Or maybe

    echo '<pre>' . var_export(array_map('htmlentities', $slide_media), true) . '</pre>';
    

    If $slidemedia is an array with html content.

    0 讨论(0)
提交回复
热议问题