Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
PHP $_POST cutting off '<' character coming from $.post in jQuery

I feel like this should be easy. The character < (and following characters) refuses to be sent to $_POST. My max_input_vars is set to 10000, my memory limit is set to 3GB in my php.ini file, and I'm using PHP 8.0.

I have a text area where the text gets posted to a PHP file.

# HTML
<div class="add-comment">
    <textarea style="margin-left: -15px;" placeholder="Add your commentary here" style="white-space:pre-wrap;" id="add-comment" class="form-control" rows="3"></textarea>
</div>

# JS
let comment = $('#add-comment').val();
const post_variables = {
    'comment' : comment   
};
console.log(post_variables);
$.post('/?c=comments&a=add_comment', post_variables, function(data){});

# PHP
echo '<pre>post:<br>';
print_r($_POST);
echo '</pre>';

Lets say I submit the text 'a < b'.

In JS, the log shows: a < b

In PHP the log shows: a

Is there something I need to do before passing it off to PHP? I'm genuinely surprised I haven't run into this before..

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can print the "<" on PHP using print_r(htmlspecialchar($_POST['comment'])) and if you want to convert it before sending to PHP use below function

# JS
function htmlEntities(str) {
    return String(str).replace(/&/g, '&amp;').replace(/</g,'&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}


let comment = $('#add-comment').val();
const post_variables = {
    'comment' : htmlEntities(comment)   
};
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda