Ryan Claxton Ryan Claxton - 1 year ago 69
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';

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download