]> git.mjollnir.org Git - moodle.git/commitdiff
Fixed some formatting problems (not caused by my last checkin!)
authormoodler <moodler>
Sat, 22 Jan 2005 02:40:07 +0000 (02:40 +0000)
committermoodler <moodler>
Sat, 22 Jan 2005 02:40:07 +0000 (02:40 +0000)
  - <hr> and <br> weren't being processed.
  - Now, space runs are replaced differently which makes code look better.

lib/html2text.php

index 55eaeb645757aabb0cb7e736c489bf1cc721cfc9..14f13ec93ef1a4f517ba277c97062ddd0a24789b 100644 (file)
@@ -91,7 +91,7 @@ function html2text( $badStr ) {
 
     //now that the page is valid (I hope) for strip_tags, strip all unwanted tags
 
-    $goodStr = strip_tags( $goodStr, '<title><hr /><h1><h2><h3><h4><h5><h6><div><p><pre><sup><ul><ol><br /><dl><dt><table><caption><tr><li><dd><th><td><a><area><img><form><input><textarea><button><select><option>' );
+    $goodStr = strip_tags( $goodStr, '<title><hr><h1><h2><h3><h4><h5><h6><div><p><pre><sup><ul><ol><br><dl><dt><table><caption><tr><li><dd><th><td><a><area><img><form><input><textarea><button><select><option>' );
 
     //strip extra whitespace except between <pre> and <textarea> tags
 
@@ -102,7 +102,7 @@ function html2text( $badStr ) {
             $goodStr = preg_split( "/<\/?textarea[^>]*>/i", $badStr[$x] );
             for ( $z = 0; isset($goodStr[$z]) && is_string( $goodStr[$z] ); $z++ ) { // Moodle: added isset() test
                 if ( $z % 2 ) { $goodStr[$z] = '<textarea>'.$goodStr[$z].'</textarea>'; } else {
-                    $goodStr[$z] = preg_replace( "/\s+/", ' ', $goodStr[$z] );
+                    $goodStr[$z] = str_replace('  ', ' ', $goodStr[$z] );
                 }
             }
             $badStr[$x] = implode('',$goodStr);
@@ -154,11 +154,17 @@ function html2text( $badStr ) {
     //wordwrap
 
     // $goodStr = wordwrap( $goodStr );   // Moodle
-    $goodStr = wordwrap( $goodStr, 70 );
+    $goodStr = wordwrap( $goodStr, 78 );
 
     //make sure there are no more than 3 linebreaks in a row and trim whitespace
-
-    return preg_replace( "/^\n*|\n*$/", '', preg_replace( "/[ \t]+(\n|$)/", "$1", preg_replace( "/\n(\s*\n){2}/", "\n\n\n", preg_replace( "/\r\n?|\f/", "\n", str_replace( chr(160), ' ', $goodStr ) ) ) ) );
+    $goodStr = str_replace(chr(160), ' ', $goodStr );
+    $goodStr = preg_replace("/\r\n?|\f/", "\n", $goodStr);
+    $goodStr = preg_replace("/\n(\s*\n){2}/", "\n\n\n", $goodStr);
+    $goodStr = preg_replace("/[ \t]+(\n|$)/", "$1", $goodStr);
+    $goodStr = preg_replace("/^\n*|\n*$/", '', $goodStr);
+    $goodStr = str_replace(chr(160), ' ', $goodStr );
+
+    return $goodStr;
 
 }