I am trying to make multiple replacements to a string (php variable) using javascript. This code:
<script>
jQuery(document).ready(function() {
var map = {
"2014": "",
"2015": "",
"2016": "",
"-": " ",
"ú": "u"
};
var str = "<?php echo $data; ?>";
var result = str.replace(/[<?php echo $data; ?>]/g, function(m) {
return replacements[m];
});
jQuery('.even_data').html(result);
});
</script>
Gives me the error:
invalid range in character class
var result = str.replace(/[2014-08-28]/g, function(m) {
^
An alternative will be to use:
jQuery(document).ready(function() {
var str = "<?php echo $data; ?>";
var result = str.replace('2014','');
jQuery('.even_data').html(result);
});
But how can you make multiple replacements?
Thanks!
I tried these answers but they did not work: Javascript str_replace many at once