[Tool/Web/Other] [PHP] PAWN Indentation
#1

Script Indentation

Introduction
This is just a VERY simple PHP script that indents any text that's inputted into the text box. I'm slightly inexperienced with PHP since I'm a beginner, so that's why it looks like shit.

How it works
It works by automatically inserting 4 spaces in front of each unindentated piece of code - or tries to fix it. Also works well with opening braces.

I can't get this to work for some reason:

pawn Код:
new
    a,
    b,
    c;
But I'm trying to make it work. It shouldn't be hard, since it works with other code, right?

Images
Since my web host is down, I only have images, sorry.



Which then outputs the following code after pressing the 'Indent' button:

pawn Код:
public OnPlayerConnect(playerid)
{
    if (IsPlayerNPC(playerid))
    {
        return 1;
    }
    else
    {
        SendClientMessageToAll(-1, "Wow, a player connected!");
    }    
    return 1;
}
It also works tough on multiple opening braces!



Output:

pawn Код:
public OnPlayerConnect(playerid)
{
    if (TestIndentation())
    {
        if(TestIndentation())
        {
            if(TestIndentation())
            {
                if(TestIndentation())
                {
                }
            }
        }
    }
    return 1;
}
Download
indent.zip

If I did anything wrong, please point it out! I'm planning on learning more about PHP and I want to know what's right - thank you!
Reply
#2

Useful.

You might want to fix the 'output':
Reply
#3

Quote:
Originally Posted by tyler12
Посмотреть сообщение
Useful.

You might want to fix the 'output':
I don't get what you mean about "fixing the output", sorry.

And thanks by the way!
Reply
#4

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
I don't get what you mean about "fixing the output", sorry.

And thanks by the way!
The output is different from the code in the image; it should be:

pawn Код:
public OnPlayerConnect(playerid)
{
    if( IsPlayerNPC(playerid))
    {
        return 1;
    }
    else SendClientMessageToAll(0xFFFFFF,"A player connected!");
    return 1;
}
edit;
Reply
#5

Oh, woops. I was testing it multiple times and I guess I inserted the wrong code. Thanks!
Reply
#6

Haven't tested it. However, how much of lining could it take before an overload of heap? Seems useful however.
Reply
#7

Quote:
Originally Posted by Akira297
Посмотреть сообщение
Haven't tested it. However, how much of lining could it take before an overload of heap? Seems useful however.
It seems to work good on a 25,000 line script. However, it completely broke on one of the other scripts I had, so I'll have to fix that up right away.

I wouldn't recommend using this for over 5,000 lines. This was just a tool I made for personal use to indent some of the small scripts I had.
Reply
#8

PHP код:
if (!isset($_POST['IndentText']))

    echo 
"Oh shit, an error occurred.";
    return 
0;

If you are trying to prevent the rest of the PHP from continuing on, I'd suggest doing this rather than returning 0. (I don't even think 'return 0' will stop the script from executing)

PHP код:
if (!isset($_POST['IndentText']))

   die(
"Oh shit, an error occurred.");

Also, indent.php can be a .html file since it doesn't execute any PHP within the file.

I like it though, very useful.
Reply
#9

Alright, version 2 is now released. This script no longer breaks on multidimensional arrays!

Quote:
Originally Posted by Memoryz
Посмотреть сообщение
PHP код:
if (!isset($_POST['IndentText']))

    echo 
"Oh shit, an error occurred.";
    return 
0;

If you are trying to prevent the rest of the PHP from continuing on, I'd suggest doing this rather than returning 0. (I don't even think 'return 0' will stop the script from executing)

PHP код:
if (!isset($_POST['IndentText']))

   die(
"Oh shit, an error occurred.");

Also, indent.php can be a .html file since it doesn't execute any PHP within the file.

I like it though, very useful.
Thanks for the info! I've just updated the script. I was also thinking of implementing both of them in one, so when someone presses "Indent", the code will automatically be indented without redirecting to a new page.
Reply
#10

lel php...

Javascript plz.
Reply
#11

Quote:
Originally Posted by Djole1337
Посмотреть сообщение
lel php...

Javascript plz.
You don't need to enter a thread labelled "PHP" and throw around your stubborn mentality, comparing a server-side language to a client-side language, not to mention you wrote "LOL" incorrectly.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)