Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $file_input = '1.rtf';
- #$dat = file_get_contents($file_input);
- $dat = '{rtf1 ololo {blah1 ololo lololo {tb ab}} homoto {td aaa}}';
- echo "<textarea style='width: 100%;'>$dat</textarea>";
- $replaces = 0;
- function parse(&$dat, &$rc)
- {
- $s = preg_match('/\{(.*)?(.*)?\}/', $dat, $sub);
- if (($rc == 5) || ($s == 0)) return;
- else {
- $rc++;
- $dat = preg_replace_callback('/\{(.*)?(.*)?\}/', function($d){
- $s = $d[0];
- preg_match('/^\{\w*/', $s, $tag);
- $tag = ltrim($tag[0], '{ ');
- $s = preg_replace('/^\{\w*/', '<' . $tag . '>', $s);
- $sl = strlen($s);
- $ot = 0;
- $et = 0;
- for ($i=0; $i<$sl; $i++) {
- if ($s[$i] == '{') {
- $ot++;
- } elseif ($s[$i] == '}') {
- --$ot;
- $et = $i;
- }
- if (($ot == -1) && ($et > 0)) break;
- }
- $s1 = substr($s, 0, $et);
- $s1 .= '</' . $tag . '>';
- $s = $s1 . substr($s, $et + 1, $sl - $et);
- return $s;
- }, $dat, 1);
- parse($dat, $rc);
- }
- }
- parse($dat, $replaces);
- echo "<textarea style='width: 100%;'>$dat</textarea>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement