1. Halo Guest, pastikan Anda selalu menaati peraturan forum sebelum mengirimkan post atau thread baru.

[Tanya] HTML Encode

Discussion in 'Pemrograman Web' started by fherryfherry, Mar 20, 2011.

Thread Status:
Not open for further replies.
  1. fherryfherry

    fherryfherry WebDev

    Joined:
    Dec 8, 2010
    Messages:
    315
    Likes Received:
    112
    Location:
    websprogramming.com
    haloo mas mbak, maaf ngrepotin mau tanya lagi nih....
    saya punya script php nih yang gunanya buat Encode HTML ...

    nah code yang saya gunakan :
    encode_html.html :
    Code:
    <form action="proses.php" method="post">
    <textarea name="htmlkode" cols="50" rows=50"></textarea></br>
    <input type="submit" value="Encode!"/>
    </form>
    
    

    proses.php :
    Code:
    <?
    text = $_POST['htmlkode'];
    $encoding = htmlentities($text);
    echo '<textarea cols=50 rows=50>'.$encoding.'</textarea>';
    ?>
    
    Nah yang jadi masalah ada setelah di proses, kok malah hasilnya tetep aja kayak semula belum ada proses encodingnya,,, malah dihasil muncul tanda '/' pada setiap sebelum ' " ' .

    contoh :
    Code:
    <font color="green">Teks disini</font>
    Hasil :
    Code:
    <font color=\"green\">Teks Disini</font>
    Sudah saya coba ganti fungsi htmlentities,htmlspecialchars,str_replace,,, tetep aja gag mempan ... kira2 kenapa ya gan .....


    sebelumnya makasih .....
     
  2. ewwink

    ewwink Super Hero

    Joined:
    Apr 27, 2006
    Messages:
    2,836
    Likes Received:
    1,100
    Location:
    Tasikmalaya, Sunda, Indonesia
    klo outputnya dihtml area harus 2 kali escapenya (htmlentities) jadi:
    PHP:
    <?
    text $_POST['htmlkode'];
    $encoding htmlentities(htmlentities($text))
    echo 
    '<textarea cols=50 rows=50>'.$encoding.'</textarea>';
    ?>
    kecuali outputnya text/plain bisa 1 kali.
     
  3. fherryfherry

    fherryfherry WebDev

    Joined:
    Dec 8, 2010
    Messages:
    315
    Likes Received:
    112
    Location:
    websprogramming.com
    wahhh makasih nih mas,, bisaa :) ....
    tapi masih ada karakter garis miringnya bila yang di input ada " atau ' , gimana ya cara ngilangin garis miring nya ....

    jadi misal &lt;a href=\"http://black.com\"&gt;teks&lt;/a&gt; <---- nah disana ada garis miring sebelum tanda " , ngilanginnya gimana ya
     
  4. ewwink

    ewwink Super Hero

    Joined:
    Apr 27, 2006
    Messages:
    2,836
    Likes Received:
    1,100
    Location:
    Tasikmalaya, Sunda, Indonesia
    ngilanginnya pake stripslashes
    PHP:
    <?php
    $text 
    stripslashes($_POST['htmlkode']);
    $encoding htmlentities(htmlentities($text));
    ?>
    <html>
    <head>
    <body>
    belum di encode:
    <form action="<?php $_SERVER['php_self'?>" method="post">
    <textarea name="htmlkode" cols="50" rows=20"><?php echo $text?></textarea></br>
    <input type="submit" value="Encode!"/>
    </form>
    hasil encode<br  />
    <textarea name="htmlkode" cols="50" rows=20"><?php echo $encoding?></textarea></br>
    </body>
    </head></html>
     
  5. fherryfherry

    fherryfherry WebDev

    Joined:
    Dec 8, 2010
    Messages:
    315
    Likes Received:
    112
    Location:
    websprogramming.com
    Wah oke punya,,, makasih banget ya mas akhirnya masalah teratasi :)
     
Thread Status:
Not open for further replies.

Share This Page