1<?php
2// $Header: /cvsroot/html2ps/xhtml.p.inc.php,v 1.6 2005/09/04 08:03:21 Konstantin Exp $
3
4function process_p($sample_html) {
5  $open_regexp = implode("|",
6    array(
7      "p","dl","div","noscript","blockquote","form","hr","table","fieldset","address",
8      "ul","ol","li",
9      "h1","h2","h3","h4","h5","h6",
10      "pre", "frameset", "noframes"
11    )
12  );
13  $close_regexp = implode("|",
14    array(
15      "dl","div","noscript","blockquote","form","hr","table","fieldset","address",
16      "ul","ol","li",
17      "h1","h2","h3","h4","h5","h6",
18      "pre", "frameset", "noframes", "body"
19    )
20  );
21  $open = mk_open_tag_regexp("(".$open_regexp.")");
22  $close = mk_close_tag_regexp("(".$close_regexp.")");
23
24  $offset = 0;
25  while (preg_match("#^(.*?)(<\s*p(\s+[^>]*?)?>)(.*?)($open|$close)#is",substr($sample_html, $offset), $matches)) {
26    if (!preg_match("#<\s*/\s*p\s*>#is",$matches[3])) {
27      $cutpos = $offset + strlen($matches[1]) + strlen($matches[2]) + strlen($matches[4]);
28      $sample_html = substr_replace($sample_html, "</p>", $cutpos, 0);
29      $offset = $cutpos+4;
30    } else {
31      $offset += strlen($matches[1])+1;
32    };
33  };
34
35  return $sample_html;
36};
37
38?>