php string replace function

Solution:

You don’t need to write any function because you have a preg_replace.

You need to add this code

$newSqlFilter = preg_replace('/([^(\s]*?)[ ]{0,}=/', 'post.\0', $sqlFilter);

And the other thing – close your query string with " character.