Find and Replace Regular Expression
I find myself creating a fair amount of forms for websites. I normally want to grab the $_POST variables and assign them to local variables. I found a relatively easy way to do this using the power of TextMates Regular Expression Search and Replace. Once the form is created I submit it, dump the $_POST array between some ‘pre’ tags and grab the output. Paste the output into your file and do the following search and replace. Don’t forget to check the ‘Regular Expressions’ box.
In the ‘Find’ Box:
[(.?*)] => (.?*)
In the ‘Replace’ Box:
$$1 = $_POST['$1'];
Turn this:
[field_1] => asdfa
[field_2] => sdfas
[field_3] => dfasd
[field_4] => fasdfasf
Into this:
$field_1 = $_POST['field_1'];
$field_2 = $_POST['field_2'];
$field_3 = $_POST['field_3'];
$field_4 = $_POST['field_4'];