| 1260 | /** |
| 1261 | * strip_html_newlines() - Strip unnecessary newlines from HTML code |
| 1262 | * |
| 1263 | * This function removes any unnecessary newlines in HTML |
| 1264 | * code. Useful for cleaning up RSS feeds before import. |
| 1265 | * |
| 1266 | * @since 2.5 |
| 1267 | * |
| 1268 | * @param string $text The HTML code to strip newlines from |
| 1269 | * @return string $text with newlines stripped |
| 1270 | */ |
| 1271 | function strip_html_newlines($text) { |
| 1272 | $textarr = preg_split("/(<[^>]+>)/Us", $text, -1, PREG_SPLIT_DELIM_CAPTURE); |
| 1273 | $stop = count($textarr); $skip = false; $output = ''; // loop stuff |
| 1274 | for ($ci = 0; $ci < $stop; $ci++) { |
| 1275 | $curl = $textarr[$ci]; |
| 1276 | if (! $skip && isset($curl{0}) && '<' != $curl{0}) { // If it's not a tag |
| 1277 | $curl = preg_replace('/[\n\r]+/', ' ', $curl); |
| 1278 | } elseif (strpos($curl, '<code') !== false || strpos($curl, '<pre') !== false || strpos($curl, '<kbd') !== false || strpos($curl, '<style') !== false || strpos($curl, '<script') !== false) { |
| 1279 | $next = false; |
| 1280 | } else { |
| 1281 | $next = true; |
| 1282 | } |
| 1283 | $output .= $curl; |
| 1284 | } |
| 1285 | return $output; |
| 1286 | } |
| 1287 | |