textCompress v0.1beta

Made for fun and to challenge myself.

class textData{
    public $arrData = array(‘array data for compression’)
        public function compress($inData){
        $compress = str_replace(array_keys($this->arrData), $this->arrData, $inData);
        return $compress;
        }
    public function extract($inData){
        $extract = str_replace($this->arrData, array_keys($this->arrData), $inData);
        return $extract;
        }
    }

example:

    $someText = “To Sherlock Holmes she is always the woman. I have seldom heard him mention her under any other name. In his eyes she eclipses and predominates the whole of her sex. It was not that he felt any emotion akin to love for Irene Adler. All emotions, and that one particularly, were abhorrent to his cold, precise but admirably balanced mind. He was, I take it, the most perfect reasoning and observing machine that the world has seen, but as a lover he would have placed himself in a false position. He never spoke of the softer passions, save with a gibe and a sneer. They were admirable things for the observer–excellent for drawing the veil from men’s motives and actions. But for the trained reasoner to admit such intrusions into his own delicate and finely adjusted temperament was to introduce a distracting factor which might throw a doubt upon all his mental results.”;
    $co = new textData();
    echo $co->compress($someText);

This will result:

    To Sherlock Holmes e^6 w6 the m5. I v4 seldom a4d him mention her d5 any h5 m4. In his eyes she eclipses _& predominates the o5 of her sex. It was not a4 he l4 any et6 akin to v4 for Irene Adler. All et6s, _& a4 one r4icularly, r4 abhorrent to his l4, precise but admirably balanced n4. He was, I k4 it, the s4 perfect a6ing _& observing c7 a4 the r5 has seen, but as a le4 he u5 v4 a5d himl4 in a false s8. He v5 o5 of the f4er s4ions, v4 t4 a gibe _& a sneer. They r4 admirl4 i5s for the obr5r–exl4ent for a4ing the veil o4 men’s motives _& actions. But for the ti4ed a6er to admit c4 intrusions into his own delicate _& n4ly ads4ed temperament was to introduce a distracting c4or i5 g5 r5 a doubt upon all his mental s6s.
    echo $co->extract($co->compress($someText));

This will return the original text.

This method will reduce space taken by any text with 10-20%.

This is training beta for now :)

download textCompress.php