str_replace generating error Array to string Conversion

Asked

Viewed 576 times

1

I am trying to change some characters demonstrated in array by empty space but the code causes me the following error:

Array to string Conversion

str_replace($string, array(',', '.'), '')

I see no mistake, which could be?

1 answer

3


The problem is that the arguments are in the wrong order, $string must be the last because it is the string to be replaced.

The first argument $serach is which(ais) characters should be found, $replace is and by which(s) should be replaced and $subject is the string or variable to replace, $count is the number of replacements.

Mixed str_replace ( Mixed $search , Mixed $replace , Mixed $Subject [, int &$Count ] )

$string = '100,39';
echo str_replace(array(',', '.'), '', $string);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.