PO::prepend_each_line() WordPress Method

The PO::prepend_each_line() Wordpress method allows you to add a string to the beginning of each line in a given string. This is useful for adding indentation or line breaks.

PO::prepend_each_line( string $string, string $with ) #

Inserts $with in the beginning of every new line of $string and returns the modified string


Parameters

$string

(string)(Required)prepend lines in this string

$with

(string)(Required)prepend lines with this string


Top ↑

Source

File: wp-includes/pomo/po.php

		public static function prepend_each_line( $string, $with ) {
			$lines  = explode( "\n", $string );
			$append = '';
			if ( "\n" === substr( $string, -1 ) && '' === end( $lines ) ) {
				/*
				 * Last line might be empty because $string was terminated
				 * with a newline, remove it from the $lines array,
				 * we'll restore state by re-terminating the string at the end.
				 */
				array_pop( $lines );
				$append = "\n";
			}
			foreach ( $lines as &$line ) {
				$line = $with . $line;
			}
			unset( $line );
			return implode( "\n", $lines ) . $append;
		}

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.