| 1 | <form method="post"> |
|---|
| 2 | <input type="submit" style="color: black;" value="Go!" id="submit" name="submit"/><br/> |
|---|
| 3 | <textarea name="data" rows="10" cols="100"><?php echo $_POST['data']?></textarea> |
|---|
| 4 | </form> |
|---|
| 5 | |
|---|
| 6 | <?php |
|---|
| 7 | |
|---|
| 8 | echo "<hr>Text as transmitted :<br/><pre style='border:red solid 2px;'>".htmlentities($_POST['data'])."</pre>"; |
|---|
| 9 | echo "<hr>the output of wpautop()<br/><pre style='border:black solid 2px;'>".htmlentities(wpautop($_POST['data']))."</pre>"; |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | /** |
|---|
| 13 | * Replaces double line-breaks with paragraph elements. |
|---|
| 14 | * |
|---|
| 15 | * A group of regex replaces used to identify text formatted with newlines and |
|---|
| 16 | * replace double line-breaks with HTML paragraph tags. The remaining |
|---|
| 17 | * line-breaks after conversion become <<br />> tags, unless $br is set to '0' |
|---|
| 18 | * or 'false'. |
|---|
| 19 | * |
|---|
| 20 | * @since 0.71 |
|---|
| 21 | * |
|---|
| 22 | * @param string $pee The text which has to be formatted. |
|---|
| 23 | * @param int|bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true. |
|---|
| 24 | * @return string Text which has been converted into correct paragraph tags. |
|---|
| 25 | */ |
|---|
| 26 | function wpautop($pee, $br = 1) { |
|---|
| 27 | $pee = $pee . "\n"; // just to make things a little easier, pad the end |
|---|
| 28 | $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee); |
|---|
| 29 | // Space things out a little |
|---|
| 30 | $allblocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr)'; |
|---|
| 31 | $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee); |
|---|
| 32 | $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee); |
|---|
| 33 | $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines |
|---|
| 34 | if ( strpos($pee, '<object') !== false ) { |
|---|
| 35 | $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param$1>", $pee); // no pee inside object/embed |
|---|
| 36 | $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee); |
|---|
| 37 | } |
|---|
| 38 | $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates |
|---|
| 39 | // make paragraphs, including one at the end |
|---|
| 40 | $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY); |
|---|
| 41 | $pee = ''; |
|---|
| 42 | foreach ( $pees as $tinkle ) |
|---|
| 43 | $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n"; |
|---|
| 44 | $pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace |
|---|
| 45 | $pee = preg_replace('!<p>([^<]+)\s*?(</(?:div|address|form)[^>]*>)!', "<p>$1</p>$2", $pee); |
|---|
| 46 | $pee = preg_replace( '|<p>|', "$1<p>", $pee ); |
|---|
| 47 | $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag |
|---|
| 48 | $pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists |
|---|
| 49 | $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee); |
|---|
| 50 | $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee); |
|---|
| 51 | $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee); |
|---|
| 52 | $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); |
|---|
| 53 | if ($br) { |
|---|
| 54 | $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', create_function('$matches', 'return str_replace("\n", "<WPPreserveNewline />", $matches[0]);'), $pee); |
|---|
| 55 | $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks |
|---|
| 56 | $pee = str_replace('<WPPreserveNewline />', "\n", $pee); |
|---|
| 57 | } |
|---|
| 58 | $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee); |
|---|
| 59 | $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee); |
|---|
| 60 | if (strpos($pee, '<pre') !== false) |
|---|
| 61 | $pee = preg_replace_callback('!(<pre.*?>)(.*?)</pre>!is', 'clean_pre', $pee ); |
|---|
| 62 | $pee = preg_replace( "|\n</p>$|", '</p>', $pee ); |
|---|
| 63 | $pee = preg_replace('/<p>\s*?(' . '\[(wp_caption|caption|gallery|singlepic|album|nggallery|imagebrowser|slideshow|nggtags|thumb|youtube|googlevideo|gvideo|dailymotion|vimeo|veoh|viddler|metacafe|blip\.tv|bliptv|flickr video|flickrvideo|ifilm|spike|myspace|stage6|flv|quicktime|flash|videofile|video|avi|mpeg|wmv|kml_flashembed)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?\[(wp_caption|caption|gallery|singlepic|album|nggallery|imagebrowser|slideshow|nggtags|thumb|youtube|googlevideo|gvideo|dailymotion|vimeo|veoh|viddler|metacafe|blip\.tv|bliptv|flickr video|flickrvideo|ifilm|spike|myspace|stage6|flv|quicktime|flash|videofile|video|avi|mpeg|wmv|kml_flashembed)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?\[(wp_caption|caption|gallery|singlepic|album|nggallery|imagebrowser|slideshow|nggtags|thumb|youtube|googlevideo|gvideo|dailymotion|vimeo|veoh|viddler|metacafe|blip\.tv|bliptv|flickr video|flickrvideo|ifilm|spike|myspace|stage6|flv|quicktime|flash|videofile|video|avi|mpeg|wmv|kml_flashembed)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])? |
|---|
| 64 | ' . ')\s*<\/p>/s', '$1', $pee); // don't auto-p wrap shortcodes that stand alone |
|---|
| 65 | |
|---|
| 66 | return $pee; |
|---|
| 67 | } |
|---|
| 68 | ?> |
|---|