Advertisement
Guest User

problem2.php

a guest
Jan 19th, 2013
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2. require('fpdf.php');
  3. class PDF extends FPDF
  4.  
  5. function WriteHTML($sum)
  6. {
  7.     // HTML parser
  8.     $sum = str_replace("\n",' ',$sum);
  9.     $a = preg_split('/<(.*)>/U',$sum,-1,PREG_SPLIT_DELIM_CAPTURE);
  10.     foreach($a as $i=>$e)
  11.     {
  12.         if($i%2==0)
  13.         {
  14.             // Text
  15.             if($this->HREF)
  16.                 $this->PutLink($this->HREF,$e);
  17.             else
  18.                 $this->Write(5,$e);
  19.         }
  20.         else
  21.         {
  22.             // Tag
  23.             if($e[0]=='/')
  24.                 $this->CloseTag(strtoupper(substr($e,1)));
  25.             else
  26.             {
  27.                 // Extract attributes
  28.                 $a2 = explode(' ',$e);
  29.                 $tag = strtoupper(array_shift($a2));
  30.                 $attr = array();
  31.                 foreach($a2 as $v)
  32.                 {
  33.                     if(preg_match('/([^=]*)=["\']?([^"\']*)/',$v,$a3))
  34.                         $attr[strtoupper($a3[1])] = $a3[2];
  35.                 }
  36.                 $this->OpenTag($tag,$attr);
  37.             }
  38.         }
  39.     }
  40. }
  41.  
  42. $sum = 1+2;
  43.  
  44. $pdf = new PDF();
  45. $pdf->AddPage();
  46. $pdf->SetFont('Arial','B',16);
  47. WriteHTML((string)$sum);
  48. $pdf->Output();
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement