Html encode in PHP

前端 未结 4 819
感情败类
感情败类 2020-11-30 13:49

What is the easiest way to Html encode in PHP?

相关标签:
4条回答
  • 2020-11-30 14:03

    Encode.php

    <h1>Encode HTML CODE</h1>
    
    <form action='htmlencodeoutput.php' method='post'>
    <textarea rows='30' cols='100'name='inputval'></textarea>
    <input type='submit'>
    </form>
    

    htmlencodeoutput.php

    <?php
    
    $code=bin2hex($_POST['inputval']); 
    $spilt=chunk_split($code,2,"%");
    $totallen=strlen($spilt);
     $sublen=$totallen-1;
     $fianlop=substr($spilt,'0', $sublen);
    $output="<script>
    document.write(unescape('%$fianlop'));
    </script>";
    
    ?> 
    <textarea rows='20' cols='100'><?php echo $output?> </textarea> 
    

    You can encode HTML like this .

    0 讨论(0)
  • 2020-11-30 14:10

    I searched for hours, and I tried almost everything suggested.
    This worked for almost every entity :

    $input = "āžšķūņrūķīš ○ àéò ∀∂∋ ©€ ♣♦ ↠ ↔↛ ↙ ℜ℞";
    
    
    echo htmlentities($input, ENT_HTML5  , 'UTF-8');
    

    result :

    &amacr;&zcaron;&scaron;&kcedil;&umacr;&ncedil;r&umacr;&kcedil;&imacr;&scaron; &cir; &agrave;&eacute;&ograve; &forall;&part;&ReverseElement; &copy;&euro; &clubs;&diamondsuit; &twoheadrightarrow; &harr;&nrarr; &swarr; &Rfr;&rx;rx;
    
    0 讨论(0)
  • 2020-11-30 14:14

    Try this:

    <?php
        $str = "This is some <b>bold</b> text.";
        echo htmlspecialchars($str);
    ?>
    
    0 讨论(0)
  • By encode, do you mean: Convert all applicable characters to HTML entities?

    htmlspecialchars or htmlentities

    You can also use strip_tags if you want to remove all HTML tags :

    strip_tags

    Note: this will NOT stop all XSS attacks

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