Jump to content

Test Stripping


Asheeown

Recommended Posts

A concept I never have gotten, when I look at example scripts that use preg functions and look for "p@$[2!*@]" (Made Up) I can never understand it.

 

I need to decipher text coming in through a telnet connection, it's organized but I still can't seem to work it out, let me give an example:

 

This is an example of what would come in, the directives are changed for confusion purposes:

/status

Status Text

---

[Directive 1] Test message

[Directive 1] [sub Directive 1]: Test message

[Directive 1] [sub Directive 1] [sub Sub Directive 1]: Test message

[Directive 2] Something for directive 2

[Directive 3] Something for directive 3

/status

Most Recent Status

---

Now what happens in this telnet session is the following:

1. Server connects to client

2. Server sends command /status

3. The first time everything from /status to the --- is pulled

4. While the session goes along those directives are sent to the server, just little bits of information, when the server is ready to pull again and store all the information received it will send the status command again, everything from the last --- to the new --- is taken and stripped

5. All directives and sub directives can be in an array the list isn't that long

 

This is how it should come out:

Directive 1 sent "Test message"

Directive 1 sent "Test message" from Sub Directive 1

Directive 1 sent "Test message" from Sub Directive 1 by Sub Sub Directive 1

Directive 2 sent "Something for directive 2"

Directive 3 sent "Something for directive 3"

Status = Most recent status

 

If anyone could help that would be great, a tutorial on text stripping would also be fantastic, all this information is just a test the real telnet session actually makes sense to the people who know what it's doing.  Sorry for any confusion and just ask if you have any questions.

Link to comment
Share on other sites

If I use:

<?php
$Array = explode("\r\n", $Strip);
foreach($Array as $v) {
if (preg_match('/^(\[.+\])\s*(.+)\s*$/', $v, $reg)) {
	echo $reg[1] . "      " . $reg[2];
	echo "<br>";
}
}
?>

 

Just to split the string in half and separate it with a bunch of spaces it works for some

[Directive 1]      Test message

 

But doesn't for others

[Chat] Text: [in-Message Bracketed Text]      .

 

When text is enclosed in brackets further on in the text it will just separate the last character with the spaces, in this case the period.  But it does work when brackets.

[Chat] [username]      says: test message

Link to comment
Share on other sites

Okay I'm so close, please can someone help me

 

It looks like this now:

if (preg_match('/([\[.+\]])\s+(.+)/', $v, $chars)) {
	echo("$chars[1]     $chars[2]");
	echo "<br>";
}

 

It correctly splits every kind of directive, except the directive name is totally gone and only a closing bracket is shown, like below

 

]    Connected on remote

 

Should be

Status    Connected on remote

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.