WPCF7_HTMLFormatter::separate_into_chunks
Separates the given text into chunks of HTML. Each chunk must be an associative array that includes 'position', 'type', and 'content' keys.
Метод класса: WPCF7_HTMLFormatter{}
Хуков нет.
Возвращает
iterable. Iterable of chunks.
Использование
$WPCF7_HTMLFormatter = new WPCF7_HTMLFormatter(); $WPCF7_HTMLFormatter->separate_into_chunks( $input );
- $input(строка) (обязательный)
- Text to be separated into chunks.
Код WPCF7_HTMLFormatter::separate_into_chunks() WPCF7 HTMLFormatter::separate into chunks CF7 6.1.5
public function separate_into_chunks( $input ) {
$input_bytelength = strlen( $input );
$position = 0;
while ( $position < $input_bytelength ) {
$next_tag = preg_match(
'/(?:<!--.*?-->|<(?:\/?)[a-z].*?>)/is',
$input,
$matches,
PREG_OFFSET_CAPTURE,
$position
);
if ( ! $next_tag ) {
yield array(
'position' => $position,
'type' => self::text,
'content' => substr( $input, $position ),
);
break;
}
$next_tag = $matches[0][0];
$next_tag_position = $matches[0][1];
if ( $position < $next_tag_position ) {
yield array(
'position' => $position,
'type' => self::text,
'content' => substr(
$input,
$position,
$next_tag_position - $position
),
);
}
if ( '<!' === substr( $next_tag, 0, 2 ) ) {
$next_tag_type = self::comment;
} elseif ( '</' === substr( $next_tag, 0, 2 ) ) {
$next_tag_type = self::end_tag;
} else {
$next_tag_type = self::start_tag;
}
yield array(
'position' => $next_tag_position,
'type' => $next_tag_type,
'content' => substr(
$input,
$next_tag_position,
strlen( $next_tag )
),
);
$position = $next_tag_position + strlen( $next_tag );
}
}