Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author ExpressionEngine Dev Team |
Rick Ellis | 08e3812 | 2008-09-12 06:21:25 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2008, EllisLab, Inc. |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html |
| 11 | * @link http://codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * Typography Class |
| 20 | * |
| 21 | * |
| 22 | * @access private |
| 23 | * @category Helpers |
| 24 | * @author ExpressionEngine Dev Team |
| 25 | * @link http://codeigniter.com/user_guide/helpers/ |
| 26 | */ |
| 27 | class CI_Typography { |
| 28 | |
| 29 | // Block level elements that should not be wrapped inside <p> tags |
Derek Jones | fa5c410 | 2008-09-30 00:47:54 +0000 | [diff] [blame] | 30 | var $block_elements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul'; |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 31 | |
| 32 | // Elements that should not have <p> and <br /> tags within them. |
Derek Jones | fa5c410 | 2008-09-30 00:47:54 +0000 | [diff] [blame] | 33 | var $skip_elements = 'p|pre|ol|ul|dl|object|table'; |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 34 | |
| 35 | // Tags we want the parser to completely ignore when splitting the string. |
Derek Jones | fa5c410 | 2008-09-30 00:47:54 +0000 | [diff] [blame] | 36 | var $inline_elements = 'a|abbr|acronym|b|bdo|br|button|cite|code|del|dfn|em|i|img|ins|input|label|map|kbd|samp|select|span|strong|sub|sup|textarea|var'; |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 37 | |
Derek Jones | d95ebca | 2008-10-01 23:57:38 +0000 | [diff] [blame] | 38 | // whether or not to protect quotes within { curly braces } |
| 39 | var $protect_braced_quotes = FALSE; |
| 40 | |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 41 | /** |
Rick Ellis | 142f8ed | 2008-09-12 06:14:52 +0000 | [diff] [blame] | 42 | * Nothing to do here... |
| 43 | * |
| 44 | */ |
| 45 | function CI_Typography() |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | /** |
Rick Ellis | 08e3812 | 2008-09-12 06:21:25 +0000 | [diff] [blame] | 50 | * Auto Typography |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 51 | * |
Rick Ellis | 08e3812 | 2008-09-12 06:21:25 +0000 | [diff] [blame] | 52 | * This function converts text, making it typographically correct: |
| 53 | * - Converts double spaces into paragraphs. |
| 54 | * - Converts single line breaks into <br /> tags |
| 55 | * - Converts single and double quotes into correctly facing curly quote entities. |
| 56 | * - Converts three dots into ellipsis. |
| 57 | * - Converts double dashes into em-dashes. |
| 58 | * - Converts two spaces into entities |
Rick Ellis | 3bc791f | 2008-09-12 23:15:52 +0000 | [diff] [blame] | 59 | * |
| 60 | * @access public |
| 61 | * @param string |
Rick Ellis | 3bc791f | 2008-09-12 23:15:52 +0000 | [diff] [blame] | 62 | * @param bool whether to reduce more then two consecutive newlines to two |
| 63 | * @return string |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 64 | */ |
Rick Ellis | ac91bd7 | 2008-10-26 21:52:41 +0000 | [diff] [blame] | 65 | function auto_typography($str, $reduce_linebreaks = FALSE) |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 66 | { |
| 67 | if ($str == '') |
| 68 | { |
| 69 | return ''; |
| 70 | } |
Rick Ellis | 3bc791f | 2008-09-12 23:15:52 +0000 | [diff] [blame] | 71 | |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 72 | // Standardize Newlines to make matching easier |
| 73 | if (strpos($str, "\r") !== FALSE) |
| 74 | { |
| 75 | $str = str_replace(array("\r\n", "\r"), "\n", $str); |
| 76 | } |
Rick Ellis | 16e3c8c | 2008-09-11 20:12:26 +0000 | [diff] [blame] | 77 | |
| 78 | // Reduce line breaks. If there are more than two consecutive linebreaks |
| 79 | // we'll compress them down to a maximum of two since there's no benefit to more. |
Rick Ellis | 3bc791f | 2008-09-12 23:15:52 +0000 | [diff] [blame] | 80 | if ($reduce_linebreaks === TRUE) |
Rick Ellis | 16e3c8c | 2008-09-11 20:12:26 +0000 | [diff] [blame] | 81 | { |
| 82 | $str = preg_replace("/\n\n+/", "\n\n", $str); |
Rick Ellis | ac91bd7 | 2008-10-26 21:52:41 +0000 | [diff] [blame] | 83 | } |
Rick Ellis | 18bd8b5 | 2008-09-10 23:40:35 +0000 | [diff] [blame] | 84 | |
Rick Ellis | 339fab7 | 2008-09-12 06:04:39 +0000 | [diff] [blame] | 85 | // Convert quotes within tags to temporary markers. We don't want quotes converted |
| 86 | // within tags so we'll temporarily convert them to {@DQ} and {@SQ} |
Derek Jones | 0d37ed8 | 2008-10-29 22:09:27 +0000 | [diff] [blame^] | 87 | // and we don't want double dashes converted to emdash entities, so they are marked with {@DD} |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 88 | if (preg_match_all("#\<.+?>#si", $str, $matches)) |
| 89 | { |
Derek Jones | c349c51 | 2008-10-27 16:29:19 +0000 | [diff] [blame] | 90 | for ($i = 0, $total = count($matches[0]); $i < $total; $i++) |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 91 | { |
Derek Jones | c349c51 | 2008-10-27 16:29:19 +0000 | [diff] [blame] | 92 | $str = str_replace($matches[0][$i], |
Derek Jones | 0d37ed8 | 2008-10-29 22:09:27 +0000 | [diff] [blame^] | 93 | str_replace(array("'",'"','--'), array('{@SQ}', '{@DQ}', '{@DD}'), $matches[0][$i]), |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 94 | $str); |
| 95 | } |
| 96 | } |
Derek Jones | c349c51 | 2008-10-27 16:29:19 +0000 | [diff] [blame] | 97 | |
Derek Jones | d95ebca | 2008-10-01 23:57:38 +0000 | [diff] [blame] | 98 | if ($this->protect_braced_quotes === TRUE) |
| 99 | { |
| 100 | if (preg_match_all("#\{.+?}#si", $str, $matches)) |
| 101 | { |
Derek Jones | c349c51 | 2008-10-27 16:29:19 +0000 | [diff] [blame] | 102 | for ($i = 0, $total = count($matches[0]); $i < $total; $i++) |
Derek Jones | d95ebca | 2008-10-01 23:57:38 +0000 | [diff] [blame] | 103 | { |
Derek Jones | c349c51 | 2008-10-27 16:29:19 +0000 | [diff] [blame] | 104 | $str = str_replace($matches[0][$i], |
| 105 | str_replace(array("'",'"'), array('{@SQ}', '{@DQ}'), $matches[0][$i]), |
Derek Jones | d95ebca | 2008-10-01 23:57:38 +0000 | [diff] [blame] | 106 | $str); |
| 107 | } |
| 108 | } |
| 109 | } |
Derek Jones | 0d37ed8 | 2008-10-29 22:09:27 +0000 | [diff] [blame^] | 110 | |
Rick Ellis | 16e3c8c | 2008-09-11 20:12:26 +0000 | [diff] [blame] | 111 | // Convert "ignore" tags to temporary marker. The parser splits out the string at every tag |
| 112 | // it encounters. Certain inline tags, like image tags, links, span tags, etc. will be |
Rick Ellis | 339fab7 | 2008-09-12 06:04:39 +0000 | [diff] [blame] | 113 | // adversely affected if they are split out so we'll convert the opening bracket < temporarily to: {@TAG} |
Derek Jones | f2b7f62 | 2008-09-27 00:10:37 +0000 | [diff] [blame] | 114 | $str = preg_replace("#<(/*)(".$this->inline_elements.")([ >])#i", "{@TAG}\\1\\2\\3", $str); |
Rick Ellis | 16e3c8c | 2008-09-11 20:12:26 +0000 | [diff] [blame] | 115 | |
| 116 | // Split the string at every tag. This expression creates an array with this prototype: |
| 117 | // |
| 118 | // [array] |
| 119 | // { |
| 120 | // [0] = <opening tag> |
| 121 | // [1] = Content... |
| 122 | // [2] = <closing tag> |
| 123 | // Etc... |
| 124 | // } |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 125 | $chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); |
| 126 | |
Rick Ellis | 16e3c8c | 2008-09-11 20:12:26 +0000 | [diff] [blame] | 127 | // Build our finalized string. We cycle through the array, skipping tags, and processing the contained text |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 128 | $str = ''; |
| 129 | $process = TRUE; |
Rick Ellis | 3ef59b7 | 2008-09-11 21:35:39 +0000 | [diff] [blame] | 130 | $paragraph = FALSE; |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 131 | foreach ($chunks as $chunk) |
| 132 | { |
Rick Ellis | 16e3c8c | 2008-09-11 20:12:26 +0000 | [diff] [blame] | 133 | // Are we dealing with a tag? If so, we'll skip the processing for this cycle. |
| 134 | // Well also set the "process" flag which allows us to skip <pre> tags and a few other things. |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 135 | if (preg_match("#<(/*)(".$this->block_elements.").*?\>#", $chunk, $match)) |
| 136 | { |
Rick Ellis | 3ef59b7 | 2008-09-11 21:35:39 +0000 | [diff] [blame] | 137 | if (preg_match("#".$this->skip_elements."#", $match[2])) |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 138 | { |
Derek Jones | 9976587 | 2008-09-24 17:19:44 +0000 | [diff] [blame] | 139 | $process = ($match[1] == '/') ? TRUE : FALSE; |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 140 | } |
Rick Ellis | 3ef59b7 | 2008-09-11 21:35:39 +0000 | [diff] [blame] | 141 | |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 142 | $str .= $chunk; |
| 143 | continue; |
| 144 | } |
Rick Ellis | 8ca943f | 2008-10-01 01:37:59 +0000 | [diff] [blame] | 145 | |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 146 | if ($process == FALSE) |
| 147 | { |
| 148 | $str .= $chunk; |
| 149 | continue; |
| 150 | } |
| 151 | |
| 152 | // Convert Newlines into <p> and <br /> tags |
Rick Ellis | 3bc791f | 2008-09-12 23:15:52 +0000 | [diff] [blame] | 153 | $str .= $this->_format_newlines($chunk); |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Derek Jones | e07ba01 | 2008-09-25 22:14:01 +0000 | [diff] [blame] | 156 | // is the whole of the content inside a block level element? |
| 157 | if ( ! preg_match("/^<(?:".$this->block_elements.")/i", $str, $match)) |
| 158 | { |
| 159 | $str = "<p>{$str}</p>"; |
| 160 | } |
| 161 | |
Rick Ellis | 339fab7 | 2008-09-12 06:04:39 +0000 | [diff] [blame] | 162 | // Convert quotes, elipsis, and em-dashes |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 163 | $str = $this->format_characters($str); |
Derek Jones | c349c51 | 2008-10-27 16:29:19 +0000 | [diff] [blame] | 164 | |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 165 | // Final clean up |
Rick Ellis | 16e3c8c | 2008-09-11 20:12:26 +0000 | [diff] [blame] | 166 | $table = array( |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 167 | |
Rick Ellis | 16e3c8c | 2008-09-11 20:12:26 +0000 | [diff] [blame] | 168 | // If the user submitted their own paragraph tags within the text |
| 169 | // we will retain them instead of using our tags. |
Derek Jones | c349c51 | 2008-10-27 16:29:19 +0000 | [diff] [blame] | 170 | '/(<p[^>*?]>)<p>/' => '$1', // <?php BBEdit syntax coloring bug fix |
Rick Ellis | 16e3c8c | 2008-09-11 20:12:26 +0000 | [diff] [blame] | 171 | |
Rick Ellis | 25319a3 | 2008-09-11 20:13:25 +0000 | [diff] [blame] | 172 | // Reduce multiple instances of opening/closing paragraph tags to a single one |
Rick Ellis | 9da2ee9 | 2008-09-23 20:39:50 +0000 | [diff] [blame] | 173 | '#(</p>)+#' => '</p>', |
Rick Ellis | 16e3c8c | 2008-09-11 20:12:26 +0000 | [diff] [blame] | 174 | '/(<p><p>)+/' => '<p>', |
| 175 | |
| 176 | // Clean up stray paragraph tags that appear before block level elements |
Rick Ellis | 339fab7 | 2008-09-12 06:04:39 +0000 | [diff] [blame] | 177 | '#<p></p><('.$this->block_elements.')#' => '<$1', |
Rick Ellis | 16e3c8c | 2008-09-11 20:12:26 +0000 | [diff] [blame] | 178 | |
| 179 | // Replace the temporary markers we added earlier |
| 180 | '/\{@TAG\}/' => '<', |
| 181 | '/\{@DQ\}/' => '"', |
Derek Jones | 0d37ed8 | 2008-10-29 22:09:27 +0000 | [diff] [blame^] | 182 | '/\{@SQ\}/' => "'", |
| 183 | '/\{@DD\}/' => '--' |
Rick Ellis | 16e3c8c | 2008-09-11 20:12:26 +0000 | [diff] [blame] | 184 | |
| 185 | ); |
| 186 | |
Rick Ellis | 339fab7 | 2008-09-12 06:04:39 +0000 | [diff] [blame] | 187 | // Do we need to reduce empty lines? |
Rick Ellis | 3bc791f | 2008-09-12 23:15:52 +0000 | [diff] [blame] | 188 | if ($reduce_linebreaks === TRUE) |
Rick Ellis | 339fab7 | 2008-09-12 06:04:39 +0000 | [diff] [blame] | 189 | { |
| 190 | $table['#<p>\n*</p>#'] = ''; |
| 191 | } |
| 192 | else |
| 193 | { |
| 194 | // If we have empty paragraph tags we add a non-breaking space |
| 195 | // otherwise most browsers won't treat them as true paragraphs |
| 196 | $table['#<p></p>#'] = '<p> </p>'; |
| 197 | } |
| 198 | |
Rick Ellis | 16e3c8c | 2008-09-11 20:12:26 +0000 | [diff] [blame] | 199 | return preg_replace(array_keys($table), $table, $str); |
| 200 | |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | // -------------------------------------------------------------------- |
| 204 | |
| 205 | /** |
| 206 | * Format Characters |
| 207 | * |
| 208 | * This function mainly converts double and single quotes |
Derek Jones | ab504b8 | 2008-09-11 17:04:30 +0000 | [diff] [blame] | 209 | * to curly entities, but it also converts em-dashes, |
| 210 | * double spaces, and ampersands |
Rick Ellis | 3bc791f | 2008-09-12 23:15:52 +0000 | [diff] [blame] | 211 | * |
| 212 | * @access public |
| 213 | * @param string |
| 214 | * @return string |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 215 | */ |
| 216 | function format_characters($str) |
Derek Jones | ab504b8 | 2008-09-11 17:04:30 +0000 | [diff] [blame] | 217 | { |
| 218 | static $table; |
| 219 | |
| 220 | if ( ! isset($table)) |
| 221 | { |
| 222 | $table = array( |
| 223 | // nested smart quotes, opening and closing |
| 224 | // note that rules for grammar (English) allow only for two levels deep |
| 225 | // and that single quotes are _supposed_ to always be on the outside |
| 226 | // but we'll accommodate both |
| 227 | '/(^|\W|\s)\'"/' => '$1‘“', |
| 228 | '/\'"(\s|\W|$)/' => '’”$1', |
| 229 | '/(^|\W|\s)"\'/' => '$1“‘', |
| 230 | '/"\'(\s|\W|$)/' => '”’$1', |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 231 | |
Derek Jones | ab504b8 | 2008-09-11 17:04:30 +0000 | [diff] [blame] | 232 | // single quote smart quotes |
| 233 | '/\'(\s|\W|$)/' => '’$1', |
| 234 | '/(^|\W|\s)\'/' => '$1‘', |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 235 | |
Derek Jones | ab504b8 | 2008-09-11 17:04:30 +0000 | [diff] [blame] | 236 | // double quote smart quotes |
| 237 | '/"(\s|\W|$)/' => '”$1', |
| 238 | '/(^|\W|\s)"/' => '$1“', |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 239 | |
Derek Jones | ab504b8 | 2008-09-11 17:04:30 +0000 | [diff] [blame] | 240 | // apostrophes |
| 241 | "/(\w)'(\w)/" => '$1’$2', |
| 242 | |
| 243 | // Em dash and ellipses dots |
| 244 | '/\s?\-\-\s?/' => '—', |
Derek Jones | 9249068 | 2008-09-24 20:44:34 +0000 | [diff] [blame] | 245 | '/(\w)\.{3}/' => '$1…', |
Derek Jones | ab504b8 | 2008-09-11 17:04:30 +0000 | [diff] [blame] | 246 | |
| 247 | // double space after sentences |
Derek Jones | 50500a2 | 2008-09-11 18:21:18 +0000 | [diff] [blame] | 248 | '/(\W) /' => '$1 ', |
Derek Jones | ab504b8 | 2008-09-11 17:04:30 +0000 | [diff] [blame] | 249 | |
| 250 | // ampersands, if not a character entity |
| 251 | '/&(?!#?[a-zA-Z0-9]{2,};)/' => '&' |
| 252 | ); |
| 253 | } |
| 254 | |
| 255 | return preg_replace(array_keys($table), $table, $str); |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | // -------------------------------------------------------------------- |
| 259 | |
| 260 | /** |
| 261 | * Format Newlines |
| 262 | * |
| 263 | * Converts newline characters into either <p> tags or <br /> |
| 264 | * |
Rick Ellis | 0de7f25 | 2008-09-12 23:22:33 +0000 | [diff] [blame] | 265 | * @access public |
| 266 | * @param string |
| 267 | * @return string |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 268 | */ |
Rick Ellis | 3bc791f | 2008-09-12 23:15:52 +0000 | [diff] [blame] | 269 | function _format_newlines($str) |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 270 | { |
| 271 | if ($str == '') |
| 272 | { |
| 273 | return $str; |
| 274 | } |
| 275 | |
| 276 | if (strpos($str, "\n") === FALSE) |
| 277 | { |
Rick Ellis | 16e3c8c | 2008-09-11 20:12:26 +0000 | [diff] [blame] | 278 | return $str; |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 279 | } |
Rick Ellis | 9da2ee9 | 2008-09-23 20:39:50 +0000 | [diff] [blame] | 280 | |
| 281 | // Convert two consecutive newlines to paragraphs |
| 282 | $str = str_replace("\n\n", "</p>\n\n<p>", $str); |
| 283 | |
| 284 | // Convert single spaces to <br /> tags |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 285 | $str = preg_replace("/([^\n])(\n)([^\n])/", "\\1<br />\\2\\3", $str); |
| 286 | |
Rick Ellis | 9da2ee9 | 2008-09-23 20:39:50 +0000 | [diff] [blame] | 287 | // Wrap the whole enchilada in enclosing paragraphs |
Rick Ellis | c95c7e9 | 2008-10-22 20:17:21 +0000 | [diff] [blame] | 288 | if ($str != "\n") |
| 289 | { |
| 290 | $str = '<p>'.$str.'</p>'; |
| 291 | } |
Rick Ellis | 9da2ee9 | 2008-09-23 20:39:50 +0000 | [diff] [blame] | 292 | |
| 293 | // Remove empty paragraphs if they are on the first line, as this |
| 294 | // is a potential unintended consequence of the previous code |
| 295 | $str = preg_replace("/<p><\/p>(.*)/", "\\1", $str, 1); |
| 296 | |
| 297 | return $str; |
Rick Ellis | 18bd8b5 | 2008-09-10 23:40:35 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Rick Ellis | 9907df4 | 2008-09-12 07:22:21 +0000 | [diff] [blame] | 300 | // ------------------------------------------------------------------------ |
| 301 | |
| 302 | /** |
| 303 | * Convert newlines to HTML line breaks except within PRE tags |
| 304 | * |
| 305 | * @access public |
| 306 | * @param string |
| 307 | * @return string |
| 308 | */ |
| 309 | function nl2br_except_pre($str) |
| 310 | { |
| 311 | $ex = explode("pre>",$str); |
| 312 | $ct = count($ex); |
| 313 | |
| 314 | $newstr = ""; |
| 315 | for ($i = 0; $i < $ct; $i++) |
| 316 | { |
| 317 | if (($i % 2) == 0) |
| 318 | { |
| 319 | $newstr .= nl2br($ex[$i]); |
| 320 | } |
| 321 | else |
| 322 | { |
| 323 | $newstr .= $ex[$i]; |
| 324 | } |
| 325 | |
| 326 | if ($ct - 1 != $i) |
| 327 | $newstr .= "pre>"; |
| 328 | } |
| 329 | |
| 330 | return $newstr; |
| 331 | } |
| 332 | |
Rick Ellis | 4c938ae | 2008-09-10 22:58:38 +0000 | [diff] [blame] | 333 | } |
| 334 | // END Typography Class |
| 335 | |
| 336 | /* End of file Typography.php */ |
| 337 | /* Location: ./system/libraries/Typography.php */ |