Skip to content

Instantly share code, notes, and snippets.

@lytithwyn
Created May 3, 2011 22:12
Show Gist options
  • Save lytithwyn/954374 to your computer and use it in GitHub Desktop.
Save lytithwyn/954374 to your computer and use it in GitHub Desktop.
code for PHP Code Formatting with sed blog post
# this line reads the whole file in so we can do multiline substitution
:a;N;$!ba;
# this gets rid of our 5 line breaks between functions
s/\n\n\n\n\n/\n\n/g
# this puts curly braces on the same line with the control structures/function definitions to which they belong
# be aware that if there is a set of lines like this:
#
# if(myTest) //here's some documentation
# {
# next line of code
# ...
#
# the curly brace will end up in the end of the comment; watch out for that
s/\n[ ]*{/ {/g
<?php
function myFunc($arg) {
print("some stuff");
if($arg == 2) {
print("Arg is 2!");
}
}
function myFunc2() {
print("I'm func 2!");
}
?>
<?php
function myFunc($arg)
{
print("some stuff");
if($arg == 2)
{
print("Arg is 2!");
}
}
function myFunc2()
{
print("I'm func 2!");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment