: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$ancestors = (array) $family['ancestors'];
$descendants = (array) $family['descendants'];
if ( in_array( $tag_name, $descendants ) ) {
$intersect = array_intersect(
array_slice( $stacked_elements, 0, $tag_position )
if ( $intersect ) { // Ancestor appears after descendant.
while ( $element = array_shift( $this->stacked_elements ) ) {
$this->append_end_tag( $element );
if ( $element === $tag_name ) {
public function close_all_tags() {
while ( $element = array_shift( $this->stacked_elements ) ) {
$this->append_end_tag( $element );
* Appends an end tag to the output property.
* @param string $tag_name Tag name.
public function append_end_tag( $tag_name ) {
if ( ! in_array( $tag_name, self::p_child_elements ) ) {
// Remove unnecessary <br />.
$this->output = preg_replace( '/\s*<br \/>\s*$/', '', $this->output );
$this->output = rtrim( $this->output ) . "\n";
if ( $this->options['auto_indent'] ) {
$this->output .= self::indent( count( $this->stacked_elements ) );
$this->output .= sprintf( '</%s>', $tag_name );
// Remove trailing <p></p>.
$this->output = preg_replace( '/<p>\s*<\/p>$/', '', $this->output );
* Appends an HTML comment to the output property.
* @param string $tag An HTML comment.
public function append_comment( $tag ) {
* Returns true if it is currently inside one of HTML elements specified
* @param string|array $tag_names A tag name or an array of tag names.
public function is_inside( $tag_names ) {
$tag_names = (array) $tag_names;
foreach ( $this->stacked_elements as $element ) {
if ( in_array( $element, $tag_names ) ) {
* Returns true if the parent node is one of HTML elements specified
* @param string|array $tag_names A tag name or an array of tag names.
public function has_parent( $tag_names ) {
$tag_names = (array) $tag_names;
$parent = reset( $this->stacked_elements );
if ( false === $parent ) {
return in_array( $parent, $tag_names );
* Calculates the position of the next chunk based on the position and
* length of the current chunk.
* @param array $chunk An associative array of the current chunk.
* @return int The position of the next chunk.
public static function calc_next_position( $chunk ) {
return $chunk['position'] + strlen( $chunk['content'] );
* Outputs a set of tabs to indent.
* @param int $level Indentation level.
* @return string A series of tabs.
public static function indent( $level ) {
return str_repeat( "\t", $level );
* Normalizes a start tag.
* @param string $tag A start tag or a tag name.
* @return array An array includes the normalized start tag and tag name.
public static function normalize_start_tag( $tag ) {
if ( preg_match( '/<(.+?)[\s\/>]/', $tag, $matches ) ) {
$tag_name = strtolower( $matches[1] );
$tag_name = strtolower( $tag );
$tag = sprintf( '<%s>', $tag_name );
if ( in_array( $tag_name, self::void_elements ) ) {
// Normalize void element.
$tag = preg_replace( '/\s*\/?>/', ' />', $tag );
return array( $tag, $tag_name );
* Normalizes a paragraph of text.
* @param string $paragraph A paragraph of text.
* @param bool $auto_br Optional. If true, line breaks will be replaced
* @return string The normalized paragraph.
public static function normalize_paragraph( $paragraph, $auto_br = false ) {
$paragraph = preg_replace( '/\s*\n\s*/', "<br />\n", $paragraph );
$paragraph = preg_replace( '/[ ]+/', " ", $paragraph );