Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

208
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda