Domanda

Ho un area di testo e vorrei prendere l'ingresso dell'area di testo e fondere tutto insieme. Tutto funziona bene, tranne che è sfuggire le virgolette. Per esempio test's viene emesso come test/'s

Per risolvere questo problema ho cercato htmlenttries quali,

<?php $inputtext= $_POST['textinput'];
        $encodetext = htmlentities($inputtext);
        $finaltext = html_entity_decode($encodetext);

        echo '<p>'.$finaltext .'</p>';  ?>

Questo dovrebbe funzionare secondo la html_entity_decode manuale (a meno che non l'ho letto male che potrebbe molto probabilmente essere il caso)

È stato utile?

Soluzione

La soluzione è probabilmente per voi per togliere gli slash.

I tagli vengono aggiunti automaticamente quando i dati viene dal POST o GET. Questo è noto come magic quotes e per impostazione predefinita sono abilitati.

È possibile rimuovere queste barre utilizzando stripslashes()

<?php

$text = $_POST['txtarea']; // from textarea
if(get_magic_quotes_gpc()){
  $text = stripslashes($text);
  // strip off the slashes if they are magically added.
}
$text = htmlentities($text);
// what htmlentities here does is really to convert:
//   & to &amp;
//   " to &#039;
//  and change all < and > to &lt; and &gt; respectively. this will automatically disable html codes in the text.
echo '<pre>'.$text.'</pre>';

?>

See: http://php.net/manual/en/function.stripslashes .php

Altri suggerimenti

È necessario utilizzare $encodetext = htmlentities ($inputtext, ENT_QUOTES); che non cercare di sfuggire le virgolette singole e doppie. Guardate sotto bandiere qui: htmlentities

Assicurarsi che non sta passando il secondo parametro nelle chiamate a htmlentities e html_entity_decode. Se lo fai, che sfuggiranno / unescape cita in modo diverso. Controllare la descrizione del parametro $quote_style nella documentazione per htmlentities e html_entity_decode .

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top