Created
July 18, 2012 08:31
-
-
Save staabm/3135052 to your computer and use it in GitHub Desktop.
Email conversation parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
preg_match_all("/^((?:\h*>+\h*)*)(.*)$/m", $s, $matches, PREG_SET_ORDER); | |
$indent = 0; | |
$s = ''; | |
foreach ($matches as $match) { | |
$newIndent = substr_count($match[1], '>'); | |
$diff = $newIndent - $indent; | |
/* | |
var_dump($match[1]); | |
var_dump($newIndent); | |
var_dump($match[0]); | |
echo "<br />\n"; | |
*/ | |
if ($diff > 0) { | |
$s .= str_repeat('<div style="border:1px solid #000; padding:10px">', $diff); | |
} elseif ($diff < 0) { | |
$s .= str_repeat('</div>', -$diff); | |
} | |
$s .= $match[2] . "\n"; | |
$indent = $newIndent; | |
} | |
$s .= str_repeat('</div>', $indent); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$s = ' | |
test | |
>bla | |
>blubb | |
>>bla | |
>>blubb | |
>blob | |
test'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$s = 'sadf asdf asdfAS | |
DF as>df asdf | |
FAs df as > df | |
AS df asdf asd f | |
>> sadf asdf | |
>> sadf asdf | |
>> asdfasdf | |
>> > sadfasdfa | |
>> > asfasdfasd | |
>> > asdfasdf | |
>> sadf asdf | |
'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$s = '> hjkh k | |
> kh kjh k | |
> h kjhk h | |
>> khj kjhk jh | |
>> g kjghkjg g | |
>> uigo goi go | |
>> kjg klgolgb o | |
>>> ughoigh oöih | |
>>> ugh ough o | |
> uho hol'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$s = '> hjkh k | |
> kh kjh k | |
> | |
> h kjhk h | |
>> khj kjhk jh | |
>> g kjghkjg g | |
>> uigo goi go | |
>> kjg klgolgb o | |
>>> ughoigh oöih | |
>>> ugh ough o | |
> uho hol | |
AS df asdf asd f | |
>> sadf asdf | |
>> sadf asdf | |
>> asdfasdf | |
>> >> sadfasdfa | |
>> >> asfasdfasd | |
>> >> asdfasdf | |
>> sadf asdf'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment