-4

This is the code I am trying.

echo str_replace("¿","","¿ teste ¿ teste");

I want to find the ¿ in any given string and remove it. But, this code is not working right.

What could I be doing wrong?

EDIT:

I managed using html special code; The link: http://www.utexas.edu/learn/html/spchar.html

Thanks!

Civa
  • 1
  • 1

2 Answers2

1

It works just fine.

php -r 'echo str_replace("¿","","¿Is it Tuesday?");'

Output:

Is it Tuesday?

EDIT

You can try making sure the file itself is 100% ASCII by escaping characters:

<?php

$c  =  json_decode('"' . '\u00bf' . '"'); // the question mark

echo str_replace( $c, '', $my_string ) . "\n";

(Taken from PHP decoding and encoding json with unicode characters)

Community
  • 1
  • 1
redolent
  • 4,159
  • 5
  • 37
  • 47
1

You might be saving the php file with an encoding that does not correctly store your string. Save your php file using a UTF encoding and try again.

Slavic
  • 1,891
  • 2
  • 16
  • 27