Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
PHP $_POST cortando el carácter '<' proveniente de $.post en jQuery

Siento que esto debería ser fácil. El carácter < (y los siguientes caracteres) se niega a enviarse a $_POST . Mi max_input_vars está establecido en 10000, mi límite de memoria está establecido en 3 GB en mi archivo php.ini y estoy usando PHP 8.0.

Tengo un área de texto donde el texto se publica en un archivo PHP.

 # 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>';

Digamos que envío el texto 'a < b' .

En JS, el registro muestra: a < b

En PHP, el registro muestra: a

¿Hay algo que deba hacer antes de pasarlo a PHP? Estoy realmente sorprendido de no haberme encontrado con esto antes ...

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede imprimir el "<" en PHP usando print_r(htmlspecialchar($_POST['comentario'])) y si desea convertirlo antes de enviarlo a PHP, use la siguiente función

 # 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!