regex to replace the $ _POST ['field'] string with $ this-input-post ('field') of codeigniter

2

I am trying to find a way to replace the $_POST['INPUT'] by $this->input->post('INPUT') of codeigniter , in my editor phpstorm , using replace with the regex option enabled.

> So what's in quotation marks that is the name of input would be retained and I would just replace the $_post variables with the codeigniter function throughout the file.

    
asked by anonymous 01.06.2017 / 17:30

1 answer

4

Use this regex to capture the characters you want by separating them into 2 groups.

\$_(.*?)\['(.*?)'\]

In the substitution field use:

$this->\L$2->$1\('\U$2\')

Explanation:

The first regex will capture the values you want by separating the word post into group 1 and the word input into group 2

After this, in the substitution field, they will be used by referencing as the first catch group and for the second, resulting in

$this->input->post('INPUT')

It is worth remembering that some regex flavors do not allow the use of modifiers in replacement groups, if this is the case, you can change the replacement part to:

$this->input->$1\('$2\')

You can test your regex here

  

As mentioned by the user who asked in the comments of this   response, what solved your problem was:

\$this->input->\L$1\('\L$2\')
    
01.06.2017 / 18:34