avolquez
avolquez

Reputation: 753

How to remove the character "�" on a PHP string variable

I'm trying to remove from a string variable, a character that appeared between spaces, I used some PHP functions to do it like str_replace but nothing happens.

An example below, I show it through var_dump PHP function :

string '�I�N�S�E�R�T� �[�d�b�o�]�

If anyone can tell me a way to do this, I'd be grateful.

Upvotes: 0

Views: 131

Answers (2)

xylar
xylar

Reputation: 7663

You could try:

$str = '�I�N�S�E�R�T� �[�d�b�o�]�';
$filtered_str = filter_var($str, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH)

Demo. See: filter-var and filter.filters.sanitize

Upvotes: 1

hakre
hakre

Reputation: 197564

That is a simple string translation operation (Demo):

$string = '�I�N�S�E�R�T� �[�d�b�o�]�';
echo strtr($string, array('�' => ''));

Output:

INSERT [dbo]

However you might have the problem to actually not knowing which character that is which then would require you to properly obtain the string first. So replacing it in the after would just be the wrong place.

Upvotes: 2

Related Questions