XOOPS  2.6.0
Utilities.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  */
11 
12 namespace Xmf;
13 
26 class Utilities
27 {
28 
37  public static function purifyText($text, $keyword = false)
38  {
40  $text = str_replace('&nbsp;', ' ', $text);
41  $text = str_replace('<br />', ' ', $text);
42  $text = str_replace('<br/>', ' ', $text);
43  $text = str_replace('<br', ' ', $text);
44  $text = strip_tags($text);
45  $text = html_entity_decode($text);
46  $text = $myts->undoHtmlSpecialChars($text);
47  $text = str_replace(')', ' ', $text);
48  $text = str_replace('(', ' ', $text);
49  $text = str_replace(':', ' ', $text);
50  $text = str_replace('&euro', ' euro ', $text);
51  $text = str_replace('&hellip', '...', $text);
52  $text = str_replace('&rsquo', ' ', $text);
53  $text = str_replace('!', ' ', $text);
54  $text = str_replace('?', ' ', $text);
55  $text = str_replace('"', ' ', $text);
56  $text = str_replace('-', ' ', $text);
57  $text = str_replace('\n', ' ', $text);
58  $text = str_replace('&#8213;', ' ', $text);
59 
60  if ($keyword) {
61  $text = str_replace('.', ' ', $text);
62  $text = str_replace(',', ' ', $text);
63  $text = str_replace('\'', ' ', $text);
64  }
65  $text = str_replace(';', ' ', $text);
66 
67  return $text;
68  }
69 
79  public static function html2text($document)
80  {
81  $search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
82  "'<img.*?/>'si", // Strip out img tags
83  "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags
84  "'([\r\n])[\s]+'", // Strip out white space
85  "'&(quot|#34);'i", // Replace HTML entities
86  "'&(amp|#38);'i",
87  "'&(lt|#60);'i",
88  "'&(gt|#62);'i",
89  "'&(nbsp|#160);'i",
90  "'&(iexcl|#161);'i",
91  "'&(cent|#162);'i",
92  "'&(pound|#163);'i",
93  "'&(copy|#169);'i");
94 
95  $replace = array ("",
96  "",
97  "",
98  "\\1",
99  "\"",
100  "&",
101  "<",
102  ">",
103  " ",
104  chr(161),
105  chr(162),
106  chr(163),
107  chr(169));
108 
109  $text = preg_replace($search, $replace, $document);
110 
111  preg_replace_callback(
112  '/&#(\d+);/',
113  function ($matches) {
114  return chr($matches[1]);
115  },
116  $document
117  );
118 
119  return $text;
120  }
121 }
$text
Definition: qrrender.php:27
$search
Definition: index.php:28
static html2text($document)
Definition: Utilities.php:79
$myts
Definition: edituser.php:38
static purifyText($text, $keyword=false)
Definition: Utilities.php:37