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

Asked

Viewed 89 times

2

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

So, what’s in quotes that’s the name of input would be kept and I would just overwrite throughout the file the variables $_post by the function of codeigniter.

  • This should do: $_POST ['INPUT' ]. Just slip the metacharacters with $, [ ...

1 answer

4


Use that regex to capture the characters you want, 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 in group 1 and the word input in group 2

After this, in the substitution field, they will be used referring to \1 as the first capture group and \2 for the second, resulting in

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

It is worth remembering that some regex Flavours do not allow the use of modifiers in the 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 answer, what solved your problem was:

\$this->input->\L$1\('\L$2\')
  • only an error was made using the replacement string, the editor reported this: "You have entered malformed Replacement string: '$this->input->$1('$2')'

  • ps: if I put a bar at the beginning of the substitution string it shows the preview of the substitution but instead of "input" it puts the name of the field in place.

  • Use $this-> L$2->$1(' U$2')

  • actually in php Storm worked well using yours but I modified it a bit and it worked well \$this->input->\L$1\('\L$2\')

  • 1

    Excellent friend, I will change the update response with your, Cheers!

  • +1 interesting the implementation of \L and \U had never seen.

Show 1 more comment

Browser other questions tagged

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