I have an array with bad strings that i want to replace in certain words, currently i wrote this code to manage this but its not working as it should:
public function _clean_filename($fn)
{
if($fn === '')
return;
foreach((array)$_filename_bad_chars as $bad)
{
if(strpos($fn, $bad))
{
str_replace($bad, '', $fn);
}
}
return $fn;
}
Simptom: When i input a word with bad strings in it the function returns nothing.
How should i rewrite this code to make it functional?
$_filename_bad_charsdefined. Not in the scope of this function thats for sure$this->_filename_bad_charsand loose the(array)casting unless of course its not an array??str_replace($bad, '', $fn);returns a string, you are dumping it into the ether, see @Forseti answer