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

206
Views
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 answers
Answer question

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 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!