3 /** This file is part of KCFinder project
5 * @desc Text processing helper class
8 * @author Pavel Tzonkov <pavelc@users.sourceforge.net>
9 * @copyright 2010, 2011 KCFinder Project
10 * @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
11 * @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
12 * @link http://kcfinder.sunhater.com
17 /** Replace repeated white spaces to single space
18 * @param string $string
21 static function clearWhitespaces($string) {
22 return trim(preg_replace('/\s+/s', " ", $string));
25 /** Normalize the string for HTML attribute value
26 * @param string $string
29 static function htmlValue($string) {
31 str_replace('"', """,
32 str_replace("'", ''',
33 str_replace('<', '<',
34 str_replace('&', "&",
38 /** Normalize the string for JavaScript string value
39 * @param string $string
42 static function jsValue($string) {
44 preg_replace('/\r?\n/', "\\n",
45 str_replace('"', "\\\"",
46 str_replace("'", "\\'",
47 str_replace("\\", "\\\\",
51 /** Normalize the string for XML tag content data
52 * @param string $string
53 * @param bool $cdata */
55 static function xmlData($string, $cdata=false) {
56 $string = str_replace("]]>", "]]]]><![CDATA[>", $string);
58 $string = "<![CDATA[$string]]>";
62 /** Returns compressed content of given CSS code
66 static function compressCSS($code) {
67 $code = self::clearWhitespaces($code);
68 $code = preg_replace('/ ?\{ ?/', "{", $code);
69 $code = preg_replace('/ ?\} ?/', "}", $code);
70 $code = preg_replace('/ ?\; ?/', ";", $code);
71 $code = preg_replace('/ ?\> ?/', ">", $code);
72 $code = preg_replace('/ ?\, ?/', ",", $code);
73 $code = preg_replace('/ ?\: ?/', ":", $code);
74 $code = str_replace(";}", "}", $code);