Jump to content

Text Filter


redfox180

Recommended Posts

Hello,

does anybody know if it's possible to create a webpage where you insert text and the server will filter/modify to whatever you've programmed to do?

 

For example you copy a document similar to this into a webpage:

 

Healthy Food INC.

445 Brighton Rd, Derby...

2xmash potatoes...

etc...

 

to:

 

PTA#2MASHPOTATOES#PE$P445DERBY

 

This would be very helpful for me when I need to process invoices or financial documents quickly and insert them into the system. It accepts entry only...

 

 

Many thanks

James

 

Link to comment
Share on other sites

Yes, it's possible. I would write a sample, but I have no idea how you got from:

 

Healthy Food INC.

445 Brighton Rd, Derby...

2xmash potatoes...

etc...

 

To this:

PTA#2MASHPOTATOES#PE$P445DERBY

 

I see where 2xmash potatoes go and 445 derby, but is that it?

 

 

Link to comment
Share on other sites

ok, we use a unix based system for the airline industry but when it comes to file an invoice it's terrible and slow and I have to translate all the information to different entries.

For example to tell the system I want to file an invoice instead of a ticket I have to start with PT followed by A for items etc...

So what I am looking for is something that, given a sample text, it translates it to a ready made entry...

Cheers

Link to comment
Share on other sites

This is a better example:

 

1 TKT LONNYC BA 22DEC YCHEAP

 

FARE: GBP1

TAXES: GBP1GB  GBP10YQ

TOTAL: GBP12

 

to:

 

PTA#RWLONNYC#WWBA#NDYCHEAP#PQGBP1#DSTAX1GB$TAX10YQ

 

This is the best example I can give you without coping a full invoice

 

It is also important that php is reading lines consequentially to avoid mixing. The post you suggested me does not explain how to create a box where you can send it and get back 'translated' text. Also it is just about text replacing...

Thanks

 

Link to comment
Share on other sites

The problem with preg_replace is that it just replace given text. Unfortunately` the text changes the only thing that remains the same is the pattern. On the previous example the AIRLINE will always proceed by the CITY PAIR. So, instead of LONNYC BA could be NYCMSP NW but the layout will always be the same. This is way I am looking at something that reads consequentially adding text that will always be the same. For the city pair will always be RW, for airline WW, etc...

 

Link to comment
Share on other sites

It's one of those "just" jobs like my wife saying "If you just knock down that wall and move the doorway from here to there...".

 

So you just need to come up with a comprehensive, foolproof set of business rules to define how any variation of input format should be converted to the desired output format.

 

Then it can be coded.

Link to comment
Share on other sites

So you just need to come up with a comprehensive, foolproof set of business rules to define how any variation of input format should be converted to the desired output format.

 

The rules have already been defined by the software provider. There are about 15.

What I cannot understand from anyone is if it is something that php can handle.

At the end, it just has to ignore some part of a document and/or precede others with predefined words/numbers...

 

If it's easy to understand, given 2  or more different sentences of 4 words each, add HI to the 1st, ignore 2nd, substitute 3rd with HAVE and add 10 to 4th.

 

EX.

 

I LIKE YOUR CARS

 

BECOMES

 

HI I HAVE 10 CARS

Link to comment
Share on other sites

Because I was bored.

 

#!/usr/bin/php
<?php

    $s = "I LIKE YOUR CARS";

    $a = explode(' ',$s);

    $r = "HI ";

    for($i=0;$i<=count($a);$i++) {
        if ($i == 0) {
            $r .= $a[$i] . " ";
        } elseif ($i == 1) {
            $r .= "HAVE ";
        } elseif ($i == 2) {
            $r .= "10 ";
        } elseif ($i == 3) {
            $r .= $a[$i];
        }   
    }   

    echo "$r\n";

?>

Link to comment
Share on other sites

What I cannot understand from anyone is if it is something that php can handle.

 

Provided that you can absolutely qualify how every possible input is to be processed, php can do it easily.  The hard part - as usual - is defining all of the rules.

Link to comment
Share on other sites

Thanks thorpe, it's starting to make sense...

Now I have another problem, how can I implement that in a way that in some cases instead of reading words in a consecutive order, it can overrule it for some exceptions? For example:

 

2  LONNYC AA 9999 Y25JAN 1645 OK YCHEAP                20K -O

 

FCALC  LON AA NYC 171.61YCHEAP AA LON 171.61YCHEAP NUC343.22E

        ND ROE0.495294<                                       

 

I can use an expression to define what I want to change on the first line because they will always be placed in the same order/pattern, but when it comes to modify line 2, I cannot think of anything...

On line 2-3 I need php to think to take in consideration everything from the word FCALC to END, this is because you can have calculations of different lengths.

Thanks

 

Link to comment
Share on other sites

So we can do it for you?

 

The problem with all of this is that I haven't found a straight answer to the problem. I'm not asking how long it's going to take... I just asked whether or not was possible. I just read a couple of tutorials for php, since it's something new for me but I could not find what I'm looking for...

 

Can php create a mask like the one form this example?

 

YTR  ETKT 342 2135 538 3544 ACN QQ45414 ISSUED 31DEC07 10.11.2 SNTEN AGT 084532431 UK PNR  EWQAU CHEAP AIRLINE INC / WEB SALES< SMITH/COLIN 342 2135 538 3544< 1 LONNYC EW 1252 K 14JAN 0745 OK KCHEAP 20K O 2 NYCLON WE 3229 K 25JAN 1645 OK KCHEAP 20K O FCALC LON EW NYC 171.61KCHEAP WE LON 171.61KCHEAP NUC343.22E ND ROE0.495294< FARE GBP170.00< TAXES GBP10.00GB GBP8.00UB GBP17.20BE GBP29.60YQ< TOTAL GBP234.8< PAYM CASH GBP234.8

 

This is what I would like php to do...

 

PTQEW

#TK 342 2135 538 3544

#IS 31DEC07

#NA SMITH/COLIN

#FC LON EW NYC 171.61KCHEAP WE LON 171.61KCHEAP NUC343.22

ETC...

 

 

As you can see from the example, it's not something that php can handle with a function or a filter. In same cases it has to ignore part of the text some others identify text between two words and some others just count from the top the word number I need... For example the tkt number will always be 3rd from the beginning but the fare calculation is a long sting always different and always between FCALC and END. It also has to add those little entries proceeded by # to the filtered text.

 

Any help??

 

Link to comment
Share on other sites

I'm not asking how long it's going to take... I just asked whether or not was possible.

 

PHP has great string manipulation functionality so, yes it is possible. However, how easy it is going to be or how long its going to take to create is another question all together.

Link to comment
Share on other sites

yep, i've just spent a while reading this, yep sounds interesting little project, but it REALLY DOES NEED A RULESET, as stated there are 15 rules, but hey what are they? PHP is a programming language albeit the same as any other, so you can do almost anything any other programming language can, but if you don't know what your doing then PHP won't be much use. There again if x is here i'll go there and then if y is something i'll do that, and because of that i'll have do it again for some unknown reason, then to begger belief i'll add 42 to it and decide whether it needs a bit o'this or that, then just for good measure mix it all up just so that even I don't have the foggiest on a clear day, even though it's raining. Can anyone tell my why it can be sunny whilst it's raining? oh dear i've bungled it!

 

Maybe from redfox's 1st and 3rd posts we could decipher a pattern, yet there's a whole lot more to it, so what's the point... just provide the ruleset please!

Link to comment
Share on other sites

There again if x is here i'll go there and then if y is something i'll do that, and because of that i'll have do it again for some unknown reason, then to begger belief i'll add 42 to it and decide whether it needs a bit o'this or that, then just for good measure mix it all up just so that even I don't have the foggiest on a clear day, even though it's raining. Can anyone tell my why it can be sunny whilst it's raining? oh dear i've bungled it!

Dear god, that's just as confusing as reading redfox's posts.

Link to comment
Share on other sites

just provide the ruleset please!

 

I think there is a little confusion between what I call rules and entries. On the software I use there are rules to define how the system has to behave in different occasions. Then, there are entries, which are the fundaments on how to build a 'mask' which is nothing else then a compilation of 2/3/4 letters (called entry .There are about 180 just to file an invoice) followed by some text/data which is what will actually appear on the mask when filed.

There is some software made by IBM which can do that but unfortunately for me not in the same computing language I am using.

If you want I can write down all the entries but I don’t think it is going to solve the problem.

Someone suggested using 'strings'...?

It's not hard to write a mathematical expression to handle it but still I cannot see how to move from maths to php...

 

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.