Code design:
\n = newline
\t = tab
= space
<?php\n\tif (example) {\n\t\techo "Hello World";\n\t}\n?>
This will output:
<?php
if (example) {
echo "Hello World";
}
?>
This is my plan on making the script.
Quote
Step 1: Remove <?php and ?> (will be added later back)
Step 2: Divide the script into lines and add this to an array. $lines = array($linenumber, $linecontent, $linetype);
Example:
$lines = array(array(1, "text", "6"), array(2, "text2", "4.2"));
All types that needs to be on different lines:
0 Do not edit '/*' till '*/'. So add this to the array as new line(s).
1 When '//' till '\n' (new line) is found add this to the array as new line.
2 When ';' is found in the script, add everything between previous line and ';' to the array as a new line.
3 When 'if' till '{' must be on a new line.
4.1 When '}' and ('else' or 'elseif') and '{' is found add this to the array as new line.
4.2 Else when '}' is found, add this to the array as new line.
5 When 'foreach' till '{' is found, add this to the array as new line.
6 When 'for' till '{' is found, add this to the array as new line.
7 When 'while' till '{' is found, add this to the array as new line.
8 When 'for' till '{' is found, add this to the array as new line.
Step 3: Remove all whitespace from the array except type 0
Step 4: Add spaces and tabs according to the type:
Types with new line: 1,2
Types with new line and extra tab: 3,5,6,7,8
Types with new line and one tab less: 4.1, 4.2
Step 5: implode the script back together.
Step 6: Add <?php on the first line and ?> on the last line.
Step 2: Divide the script into lines and add this to an array. $lines = array($linenumber, $linecontent, $linetype);
Example:
$lines = array(array(1, "text", "6"), array(2, "text2", "4.2"));
All types that needs to be on different lines:
0 Do not edit '/*' till '*/'. So add this to the array as new line(s).
1 When '//' till '\n' (new line) is found add this to the array as new line.
2 When ';' is found in the script, add everything between previous line and ';' to the array as a new line.
3 When 'if' till '{' must be on a new line.
4.1 When '}' and ('else' or 'elseif') and '{' is found add this to the array as new line.
4.2 Else when '}' is found, add this to the array as new line.
5 When 'foreach' till '{' is found, add this to the array as new line.
6 When 'for' till '{' is found, add this to the array as new line.
7 When 'while' till '{' is found, add this to the array as new line.
8 When 'for' till '{' is found, add this to the array as new line.
Step 3: Remove all whitespace from the array except type 0
Step 4: Add spaces and tabs according to the type:
Types with new line: 1,2
Types with new line and extra tab: 3,5,6,7,8
Types with new line and one tab less: 4.1, 4.2
Step 5: implode the script back together.
Step 6: Add <?php on the first line and ?> on the last line.
Do you think this is possible, and what is your opinion about this?
Takumi
Edited by Takumi, 08 November 2010 - 07:24 AM.


Sign In
Create Account


Back to top









