$sql_command = "select * from table where col1 like $1 " .
"and col2 like $20 " .
"and col3 like $1and col4 like $4 " .
"and col5 = $1";

$parms = array('$1' => "parm one %", '$4' => "parm two", );


// tidy up sql_command

$sql_command = trim($sql_command);
$sql_command = preg_replace('/\s+/', ' ', $sql_command); // strip all white spaces.
$sql_command=strtoupper($sql_command);


// extract all like clause from sql command into array.

if ( preg_match_all('/ LIKE \$\d+ | LIKE \$\d+$/', $sql_command, $valid_like_clauses) < 1 )
$valid_like_clauses = array();

// replace variables in like clause with values of parms array

foreach ($parms as $key => $value) {
$value = addcslashes($value, "%_");
$valid_like_clauses=str_replace($key, $value, $valid_like_clauses);
}

I expect $1 and $4 in the $valid_like_clauses array elements to replaced with parms array value, but it doesn't happen?

Thanks for any help you can provide.

alex