2

So, many years ago when I started writing PHP code, I learned to format information sent from a form as such:

$_POST[itemnamehere];

Whether that was right or wrong at the time, it worked. However, with newer versions of PHP, the format needs to contain inverted commas inside the square brackets, like so:

$_POST['itemnamehere'];

I have literally thousands of PHP files which contain the former formatting and was hoping to find a way to bulk replace using Notepad++.

Obviously, I can't just replace [ with [' and ] with '] as there will be times when [ and ] are used without it being related to $_POST.

I figure there must be a method via regex in Notepad++, but can't seem to manage it.

Any experts have the solution?

1 Answer 1

0

The regex itself is pretty simple.

Search what : $_POST\[(.+)\]

Replace with : $_POST\['$1']

Search mode : Regular expression

\. matches newline : Off

You could use the "Find in Files" search dialog.

4
  • You need to add the inverted commas. Commented Mar 15 at 13:35
  • @ReddyLutonadio: They were there, but for formatting errors they were not displayed.
    – harrymc
    Commented Mar 15 at 13:38
  • Thank you, I was close myself but was using .* rather than (.+).
    – teddytash
    Commented Mar 15 at 13:39
  • fixed the quoting
    – DavidPostill
    Commented Mar 15 at 17:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .