Title: PO::prepend_each_line
Published: April 25, 2014
Last modified: May 20, 2026

---

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

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/po/prepend_each_line/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/po/prepend_each_line/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/po/prepend_each_line/?output_format=md#related)

[ Back to top](https://developer.wordpress.org/reference/classes/po/prepend_each_line/?output_format=md#wp--skip-link--target)

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

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/po/prepend_each_line/?output_format=md#parameters)󠁿

 `$input_string`stringrequired

prepend lines in this string

`$with`stringrequired

prepend lines with this string

## 󠀁[Source](https://developer.wordpress.org/reference/classes/po/prepend_each_line/?output_format=md#source)󠁿

    ```php
    public static function prepend_each_line( $input_string, $with ) {
    	$lines  = explode( "\n", $input_string );
    	$append = '';
    	if ( "\n" === substr( $input_string, -1 ) && '' === end( $lines ) ) {
    		/*
    		 * Last line might be empty because $input_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;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/po.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/pomo/po.php#L177)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/pomo/po.php#L177-L194)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/po/prepend_each_line/?output_format=md#related)󠁿

| Used by | Description | 
| [PO::export_headers()](https://developer.wordpress.org/reference/classes/po/export_headers/)`wp-includes/pomo/po.php` |

Exports headers to a PO entry

  | 
| [PO::comment_block()](https://developer.wordpress.org/reference/classes/po/comment_block/)`wp-includes/pomo/po.php` |

Prepare a text as a comment — wraps the lines and prepends # and a special character to each line

  |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fpo%2Fprepend_each_line%2F)
before being able to contribute a note or feedback.