PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?
function funky() {
$foo = 'bar';
$fu='bar';
return $fu . $foo;
}?>
into:
<?php
function funky ( ) {
$foo = "bar";
$fu = "bar";
return $fu.$foo;
}
?>
Has anyone seen a program/script that takes a file as input and outputs a user-specified style of php code?
There is some PHP indenting script for Vim at http://www.vim.org/scripts/script.php?script_id=1120 and in that script there are some goovy functions that do magical stuff. Maybe that can be modifed for personal use?
Well here's where im going with this... I'm planning to start a code bank site (another one of those?!?! Anywho - so I was hoping that when someone uploads a script, it could get re-formatted into a style that is the same for all the scripts on the site. Any ideas?
sounds like a regular expression nightmare I had a few nights ago....
couple problems I could see:
1) how do you determine what is the "correct" way to format the php? Maybe there could be an option to have it formatted by the users choice and all the scripts they want would then be formatted accordingly...that'd be cool
2) you're going to have to take into account an immeasurable amount of different styles. Just today for example in another thread we had a 2 page discussion on whether or not echo statements and variable declaraions should be multilined or not... I think you'd have a very difficult time accounting for everyone's different style and coding preference.
I think it's a fantastic idea and I'd love to see you go for it, but I think it'd be a tremendous amount of work and honestly I'm not sure the reward (end result) would be worth it.
I'm hoping you mean by styles that you mean appearance of code, not actual coding guidlines. If it's the former, then start by stripping all whitespace. Then, put a newline character after every '{', and indent every line until you get to a '}'. Syntax highlighting can easily be done by highlight_string().
If you truly do mean the latter, then I agree with ~Burrito - not worth the hassle.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Absolutely correct, a whole lot of work, but it would be nice to have all the files uploaded be the same format. It was be a simple format so that anyone would be able to read the code quickly.
Burrito wrote:how do you determine what is the "correct" way to format the php?
Making all the code uploaded follow your guidlines is impossible (and I don't use that term lightly). There are an infinite number of ways to do pretty much anything. Writing code to parse and conform any uploaded file would also need to be an infinite function.
I'd focus on making the spacing and highlighting work properly. If you want code conformity, just work in an approval process where you have to double check it before it gets posted.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
pickle wrote:Making all the code uploaded follow your guidlines is impossible (and I don't use that term lightly). There are an infinite number of ways to do pretty much anything. Writing code to parse and conform any uploaded file would also need to be an infinite function.
"You should never, never doubt what nobody is sure about" - Willy Wonka.
Last edited by Roja on Mon Jul 25, 2005 10:14 am, edited 1 time in total.