Regular expression to change the pair of variables in mysql in PHP file

6

What expression can I use to be able to change MYSQL function parameters, eg:

mysql_query($query,$db);

mysql_query($db,$query);

Because I search for mysql_query and change to mysqli_query after I can make that change.

That is, replace two strings that are within a parenthesis.

    
asked by anonymous 27.06.2017 / 17:24

1 answer

7

You can inveter the arguments by creating three groups at the end simply format the substitution.

The idea is to break this instruction from the following way, 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 the parentheses.

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

Search for:

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

Replace with:

\(,\)

Or:

$1\($3,$2\)
    
27.06.2017 / 17:51