Pergunta

I have a string which contains multiple "â" characters, so I made this jquery function to replace them (cannot do it server-side).

$(document).ready(function() {
       $('#tab-3').click(function(){
             $('#tab-3').html($('#tab-3').html().replace(/â/g, '•'));
       });

 });

Now this code $('#tab-3').html($('#tab-3').html().replace(/â/g, '•')); works if I run it in console, but not on page.

I must say that I get the string via curl, and the characters are like so, instead of â

Any ideas? Thanks!

UPDATE 1:

tried this:

setTimeout(function() {
        alert('mda');
        console.log($('#tab-3').html());
        $('#tab-3').html($('#tab-3').html().replace(/â/g, '•'));
}, 0);

Alert works, html() shows the content in console, the last one fails.

I'm starting to think it is the browser that prints the â character, and it may be â

Will try this theory now!

UPDATE 2

Not working, tried with â instead of â..

Another interesting thing..if i do:

setTimeout(function() {

       console.log($('#tab-3').html().replace(/â/g, '•'));

 });

or with â instead of â it prints the string as it is...only if i run the same code again in browser does it work...

I have no idea on what to do next..

here is a screenshot proving it works in browser (the red text above is the console.log i did in setTimeout function...

Console

Foi útil?

Solução

Ended up using echo iconv('UTF-8', 'ASCII//ignore',$string); I had to use //ignore because it would generate a notice..But instead of converting it to a bullet, this simply deletes the characters....

Hope this helps anyone. Thank you all for your time!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top