Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For example, the most common code maybe is something like this:

$title = $_POST['title'];
$price = $_POST['price'];
$area = $_POST['area'];
$property = $_POST['property'];
$room = $_POST['room'];
$hall = $_POST['hall'];

Is there plugin/method could ease our pain?

Thanks.

share|improve this question
1  
perhaps you should go to stackoverflow? – Rafe Kettler Sep 18 '10 at 1:57
up vote 6 down vote accepted

Here's a mapping that might help.

:imap \p <esc>diwa$<C-R>" = $_POST['<C-R>"'];

<esc> - takes you out of insert mode
diw - deletes the word under the cursor into the default register
a - puts you back into insert mode
<C-R>" - inserts the contents of the default register

When the mapping is done, you're left in insert mode, so you can just hit <enter> and continue with the next line.

To use this, type just the symbol name on a line and immediately follow it with \p.

You can put the mapping itself in your ~/.vimrc or ~/.vim/after/ftplugin/php.vim on Unix, or ~\_vimrc or ~\vimfiles\after\ftplugin\php.vim on Windows.

share|improve this answer

snipMate to the rescue!

You could just create your own snippet, something along the lines of:

${1} = $_POST['${1}'];${2}

That'll allow you to type (e.g.) "pt", hit tab, fill in "title/price/area/etc" for the variable name, and have the POST value be automagically filled in with that value. Hit tab again to be taken to the end of the line.

share|improve this answer
$props = array('title','price','area','property','room','hall');
foreach($props as $prop) $$prop = $_POST[$prop];
share|improve this answer
1  
+1 for "Write better code" – ta.speot.is Oct 1 '10 at 23:47
extract($_POST, EXTR_PREFIX_ALL, "p_");
# results in $p_title, $p_price, ...
share|improve this answer
    
Why the downvote? This is a "write better code" answer and perfectly answers the OP's question. – dotancohen Apr 21 '12 at 22:37

You must log in to answer this question.

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