Regular expression to swap the variable pair in mysql in PHP file

Asked

Viewed 117 times

6

Which expression can I use to exchange MYSQL function parameters, example:

mysql_query($query,$db);

mysql_query($db,$query);

Why I look for mysql_query and change to mysqli_query after I can make that change.

That is, change of place two strings that are within a parentheses.

1 answer

7


You can envy the arguments by creating three groups at the end just format the substitution.

The idea is to break this instruction of the following form, the first group is mysql_query the second $query and the third $db. With the captured elements reverse the order of the second with the third and add parentheses.

The first takes the instruction: (mysql_query) the second variable with the query (\$\w+), representing a dollar sign followed by one or more letters, followed by a comma and a variable.

Look for:

(mysql_query)\((\$\w+)\s*,\s*(\$\w+)\)

Replace with:

\1\(\3,\2\)

Or else:

$1\($3,$2\)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.