Make WordPress Core

Ticket #33106: patch ideas.txt

File patch ideas.txt, 1.2 KB (added by miqrogroove, 10 years ago)

Excuse the format; I wrote this in Notepad at a hotel.

Line 
1<?php
2
3function wp_html_split( $input ) {
4
5$output = array();
6$pos = 0;
7$length = strlen( $input );
8
9while ( $pos < $length ) {
10
11// Find next element.
12$start = strpos( $input, '<', $pos );
13
14// No more elements?
15if ( false === $start ) {
16        $output[] = substr( $input, $pos );
17        return $output;
18}
19
20// Capture space between elements.
21$output[] = substr( $input, $pos, $start - $pos );
22$pos = $start;
23
24// Is this an HTML comment?
25if ( substr( $input, $pos, 4 ) == '<!--' ) {
26        $end = strpos( $input, '-->', $pos );
27        if ( false === $end ) {
28                $output[] = substr( $input, $pos );
29                return $output;
30        } else {
31                $end += 3;
32                $output[] = substr( $input, $pos, $end - $pos );
33                $pos = $end;
34        }
35} elseif ( substr( $input, $pos, 9 ) == '<![CDATA[' ) {
36        $end = strpos( $input, ']]>', $pos );
37        if ( false === $end ) {
38                $output[] = substr( $input, $pos );
39                return $output;
40        } else {
41                $end += 3;
42                $output[] = substr( $input, $pos, $end - $pos );
43                $pos = $end;
44        }
45} else {
46        $end = strpos( $input, '>', $pos );
47        if ( false === $end ) {
48                $output[] = substr( $input, $pos );
49                return $output;
50        } else {
51                $end += 1;
52                $output[] = substr( $input, $pos, $end - $pos );
53                $pos = $end;
54        }
55}
56
57} // while
58
59return $output;
60
61} // function