pluginGino-mpdf
 All Data Structures Namespaces Files Functions Variables Pages
func.mpdf.php
Go to the documentation of this file.
1 <?php
43 namespace Gino;
44 
51 function htmlToPdf($string) {
52 
53  $string = htmlentities($string, ENT_QUOTES, 'UTF-8');
54 
55  return htmlspecialchars_decode($string);
56 }
57 
64 function pdfChars($string, $openclose=false)
65 {
66  $string = trim($string);
67  $string = stripslashes($string);
68  $string = convertToHtml($string);
69 
70  $string = str_replace ('&euro;', '€', $string);
71  $string = str_replace ('&', '&amp;', $string);
72  $string = str_replace ('\'', '&#039;', $string);
73  $string = preg_replace("/:/", "&#58;", $string);
74 
75  if($openclose)
76  {
77  $string = str_replace("<", "&lt;", $string);
78  $string = str_replace(">", "&gt;", $string);
79  }
80 
81  return $string;
82 }
83 
90 function pdfChars_Textarea($string)
91 {
92  $string = trim($string);
93  $string = stripslashes($string);
94  $string = convertToHtml($string);
95 
96  $string = str_replace ('&euro;', '€', $string);
97  $string = str_replace ('&bull;', '•', $string);
98  $string = htmlentities($string, ENT_QUOTES, 'UTF-8');
99 
100  $string = nl2br($string);
101 
102  return $string;
103 }
104 
111 function pdfTextChars($string)
112 {
113  $string = trim($string);
114  $string = stripslashes($string);
115  $string = convertToHtml($string);
116 
117  // Eliminare i commenti HTML
118  $string = preg_replace("#(\n*)#", "", $string);
119  $string = preg_replace("#<!--(.*)-->#", "", $string);
120 
121  //$string = preg_replace("#<br />#", "\n", $string);
122 
123  $string = str_replace ('&euro;', '€', $string);
124  $string = str_replace ('&bull;', '•', $string);
125  //$string = str_replace ('&', '&amp;', $string);
126  //$string = str_replace ('\'', '&#039;', $string);
127  //$string = preg_replace("/:/", "&#58;", $string);
128  //$string = str_replace(':', "&#58;", $string);
129 
130  // conversione in entities
131  $string = htmlentities($string, ENT_QUOTES, 'UTF-8');
132  // riconversione di alcune entities
133  $string = preg_replace('#&lt;([a-zA-Z]+)&gt;#', "<$1>", $string); // <p>
134  $string = preg_replace('#&lt;/([a-zA-Z]+)&gt;#', "</$1>", $string); // </p>
135  //$string = preg_replace('#/&gt;#', '/>', $string); // />
136  $string = preg_replace("#&lt;([a-zA-Z]+)[\s]+[\w]*/&gt;#", "<$1 />", $string); // <br />
137  $string = preg_replace("#&lt;([a-zA-Z]+)[\s]+(id|class|lang)=&quot;[\w\.\-]*&quot;[\s]*&gt;#", "<$1>", $string); // <span id="...">
138 
139  // per risolvere i problemi nel riconoscere la fine del tag 'b' quando è in prossimità di un 'br'
140  $string = preg_replace("#><br />#", ">\n<br />", $string);
141  $string = preg_replace("#<br />\n(<[a-zA-Z]+>)#", "$1\n<br />", $string);
142 
143  // problema quando non sono tag:
144  //$string = str_replace('&lt;', "<", $string);
145  //$string = str_replace('&gt;', ">", $string);
146 
147  //$string = preg_replace("#><br />#", "> <br />", $string);
148  //$string = preg_replace("#<ul>#", "<ul style=\"margin:-20px;padding:0;\">", $string);
149 
150  return $string;
151 }
152 
159 function pdfHtmlToEntities($str){
160 
161  //$txt = normalize_special_characters($str);
162  $txt = replaceChar($str);
163  $txt = htmlentities($txt, ENT_QUOTES, 'UTF-8');
164  $txt = str_replace('&euro;', chr(128), $txt);
165  $txt = html_entity_decode($txt);
166 
167  return $txt;
168 }
169 
177 function normalize_special_characters($str, $unwanted=false)
178 {
179  # Quotes cleanup
180  $str = str_replace(chr(ord("`")), "'", $str);
181  $str = str_replace(chr(ord("´")), "'", $str);
182  $str = str_replace(chr(ord("„")), ",", $str);
183  $str = str_replace(chr(ord("`")), "'", $str);
184  $str = str_replace(chr(ord("´")), "'", $str);
185  $str = str_replace(chr(ord("“")), "\"", $str);
186  $str = str_replace(chr(ord("”")), "\"", $str);
187  $str = str_replace(chr(ord("´")), "'", $str);
188 
189  $unwanted_array = array('Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y');
190  if($unwanted)
191  $str = strtr($str, $unwanted_array);
192 
193  # Bullets, dashes, and trademarks
194  $str = str_replace(chr(149), "&#8226;", $str); # bullet •
195  $str = str_replace(chr(150), "&ndash;", $str); # en dash
196  $str = str_replace(chr(151), "&mdash;", $str); # em dash
197  $str = str_replace(chr(153), "&#8482;", $str); # trademark
198  $str = str_replace(chr(169), "&copy;", $str); # copyright mark
199  $str = str_replace(chr(174), "&reg;", $str); # registration mark
200 
201  return $str;
202 }
203 
204 function htmlButTags($str)
205 {
206  // Take all the html entities
207  $caracteres = get_html_translation_table(HTML_ENTITIES);
208  // Find out the "tags" entities
209  $remover = get_html_translation_table(HTML_SPECIALCHARS);
210  // Spit out the tags entities from the original table
211  $caracteres = array_diff($caracteres, $remover);
212  // Translate the string....
213  $str = strtr($str, $caracteres);
214 
215  // now amps
216  $str = preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&amp;" , $str);
217 
218  return $str;
219 }
220 
221 function keephtml($string)
222 {
223  $res = htmlentities($string);
224  $res = str_replace("&lt;","<",$res);
225  $res = str_replace("&gt;",">",$res);
226  $res = str_replace("&quot;",'"',$res);
227  $res = str_replace("&amp;",'&',$res);
228  return $res;
229 }
230 ?>