i know there must be thousands of threads like this, but the internet and stack overflow is flooded with results from other programming languages and simply replacing the characters with a whitespace and so on...
so... my problem is as follows...
i have a form with: <input type='text' id='my_input'>
then i parse all my fields in javascript (with jquery) to create my ajax call, like this
var my_value = $('#my_input').val();
then i do a replace to get the line breaks my_value = my_value.replace('\n', '<br>');
after that i post my variables with ajax like this:
data_to_post = 'my_field1=' + my_value1 + 'my_field2' + my_value2;
$.ajax({
type: 'POST',
url: '/write_to_db.php',
data: data_to_post
});
now many people on my site talk about programming and that content started screwing up my site, because their post content gets parsed as php or as html formatting - i'm planning to replace all the problematic characters that could screw up the code of my site.
the most problematic expressions are html tags and &= because it interferes with the way i put my post variable together.
now, because those characters are necessary for the content, i can't simply replace them all with with a single character.
is there any way i could escape them (at best in a one line command)?
thanks!
UPDATE: my temporary solution is this:
this_string = this_string.replace(/</g, '<');
this_string = this_string.replace(/>/g, '>');
this_string = this_string.replace(/\n/g, '<br>');
this_string = escape(this_string);