Conditions | 2 |
Paths | 2 |
Total Lines | 14 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 2.004 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | 6 | public static function htmlToPlainText($str, $keepN = false) |
|
15 | { |
||
16 | 6 | $str = preg_replace('#<(style|script).*</(style|script)>#siU', ' ', $str); |
|
17 | 6 | $str = preg_replace('#</?(br|p|div)>#siU', "\n", $str); |
|
18 | 6 | $str = preg_replace('/<\/[a-z]+>/siU', ' ', $str); |
|
19 | 6 | $str = str_replace(["\r", "\t"], ' ', $str); |
|
20 | 6 | $str = strip_tags(preg_replace('/<[^<]+?>/', ' ', $str)); |
|
21 | 6 | if ($keepN) { |
|
22 | $str = preg_replace('/ {2,}/', ' ', $str); |
||
23 | } else { |
||
24 | 6 | $str = preg_replace('/\s+/', ' ', $str); |
|
25 | } |
||
26 | |||
27 | 6 | return $str; |
|
28 | } |
||
30 |