Major M. Mason
Major M. Mason

Reputation: 41

Find and replace using wildcard in netbeans

How would one go about using replace in netbeans to modify a PHP script with lots of $_POST[].

For better security it would be a good idea to replace all these $_POST[] with sanitize($_POST[]) where sanitize is a function that sanitizes user input.

So I could use Replace and search for $_POST[''] and replace with sanitize($_POST['']).

But how do you keep the variable name within each $_POST[''] while adding the closing parenthesis?

For example $_POST['name'] and $_POST['action'] need to become sanitize($_POST['name']) and santize($_POST['action']) respectively.

Upvotes: 4

Views: 1566

Answers (1)

WillShackleford
WillShackleford

Reputation: 7018

I am not a PHP programmer or a Regex master but in my very limited test this seemed to work.

Select the project and then choose Edit -> Replace. Choose "Regular Expression" in the drop down list, set containing text to \$_POST\[(.*)\]and replace with to sanitize(\$_POST[$1])

screenshot using regex

Upvotes: 2

Related Questions