How to display special characters in PHP

前端 未结 9 1300
野的像风
野的像风 2020-11-30 12:24

I\'ve seen this asked several times, but not with a good resolution. I have the following string:

$string = \"

Résumé

\";

相关标签:
9条回答
  • 2020-11-30 13:10

    So I try htmlspecialchars() or htmlentities() which outputs <p>Résumé<p> and the browser renders <p>Résumé<p>.

    If you've got it working where it displays Résumé with <p></p> tags around it, then just don't convert the paragraph, only your string. Then the paragraph will be rendered as HTML and your string will be displayed within.

    0 讨论(0)
  • 2020-11-30 13:11

    Try This

    Input:

    <!DOCTYPE html>
    <html>
    <body>
    
    <?php
    $str = "This is some <b>bold</b> text.";
    echo htmlspecialchars($str);
    ?>
    
    <p>Converting &lt; and &gt; into entities are often used to prevent browsers from using it as an HTML element. <br />This can be especially useful to prevent code from running when users have access to display input on your homepage.</p>
    
    </body>
    </html>
    

    Output:

    This is some <b>bold</b> text.
    
    Converting < and > into entities are often used to prevent browsers from using it as an HTML element. This can be especially useful to prevent code from running when users have access to display input on your homepage.
    
    0 讨论(0)
  • 2020-11-30 13:15

    This works for me. Try this one before the start of HTML. I hope it will also work for you.

    <?php header('Content-Type: text/html; charset=iso-8859-15'); ?>
    <!DOCTYPE html>
    
    <html lang="en-US">
    <head>

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