Ryan Claxton Ryan Claxton - 11 months ago 45
SQL Question

php string replace function

I need to write a function that takes in a long string that is a sql command and searches for an equal sign goes back to the word before it and adds "post." before it.



$sqlFilter = "WHERE sport = 'Hockey' AND team = 'New York Rangers';


$sqlFilter = "WHERE post.sport = 'Hockey' AND post.team = 'New York Rangers';


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.