Title: PO::read_entry
Published: April 25, 2014
Last modified: April 28, 2025

---

# PO::read_entry( resource $f, int $lineno ): null|false|array

## In this article

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

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

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

 `$f`resourcerequired

`$lineno`intrequired

## 󠀁[Return](https://developer.wordpress.org/reference/classes/po/read_entry/?output_format=md#return)󠁿

 null|false|array

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

    ```php
    public function read_entry( $f, $lineno = 0 ) {
    	$entry = new Translation_Entry();
    	// Where were we in the last step.
    	// Can be: comment, msgctxt, msgid, msgid_plural, msgstr, msgstr_plural.
    	$context      = '';
    	$msgstr_index = 0;
    	while ( true ) {
    		++$lineno;
    		$line = PO::read_line( $f );
    		if ( ! $line ) {
    			if ( feof( $f ) ) {
    				if ( self::is_final( $context ) ) {
    					break;
    				} elseif ( ! $context ) { // We haven't read a line and EOF came.
    					return null;
    				} else {
    					return false;
    				}
    			} else {
    				return false;
    			}
    		}
    		if ( "\n" === $line ) {
    			continue;
    		}
    		$line = trim( $line );
    		if ( preg_match( '/^#/', $line, $m ) ) {
    			// The comment is the start of a new entry.
    			if ( self::is_final( $context ) ) {
    				PO::read_line( $f, 'put-back' );
    				--$lineno;
    				break;
    			}
    			// Comments have to be at the beginning.
    			if ( $context && 'comment' !== $context ) {
    				return false;
    			}
    			// Add comment.
    			$this->add_comment_to_entry( $entry, $line );
    		} elseif ( preg_match( '/^msgctxt\s+(".*")/', $line, $m ) ) {
    			if ( self::is_final( $context ) ) {
    				PO::read_line( $f, 'put-back' );
    				--$lineno;
    				break;
    			}
    			if ( $context && 'comment' !== $context ) {
    				return false;
    			}
    			$context         = 'msgctxt';
    			$entry->context .= PO::unpoify( $m[1] );
    		} elseif ( preg_match( '/^msgid\s+(".*")/', $line, $m ) ) {
    			if ( self::is_final( $context ) ) {
    				PO::read_line( $f, 'put-back' );
    				--$lineno;
    				break;
    			}
    			if ( $context && 'msgctxt' !== $context && 'comment' !== $context ) {
    				return false;
    			}
    			$context          = 'msgid';
    			$entry->singular .= PO::unpoify( $m[1] );
    		} elseif ( preg_match( '/^msgid_plural\s+(".*")/', $line, $m ) ) {
    			if ( 'msgid' !== $context ) {
    				return false;
    			}
    			$context          = 'msgid_plural';
    			$entry->is_plural = true;
    			$entry->plural   .= PO::unpoify( $m[1] );
    		} elseif ( preg_match( '/^msgstr\s+(".*")/', $line, $m ) ) {
    			if ( 'msgid' !== $context ) {
    				return false;
    			}
    			$context             = 'msgstr';
    			$entry->translations = array( PO::unpoify( $m[1] ) );
    		} elseif ( preg_match( '/^msgstr\[(\d+)\]\s+(".*")/', $line, $m ) ) {
    			if ( 'msgid_plural' !== $context && 'msgstr_plural' !== $context ) {
    				return false;
    			}
    			$context                      = 'msgstr_plural';
    			$msgstr_index                 = $m[1];
    			$entry->translations[ $m[1] ] = PO::unpoify( $m[2] );
    		} elseif ( preg_match( '/^".*"$/', $line ) ) {
    			$unpoified = PO::unpoify( $line );
    			switch ( $context ) {
    				case 'msgid':
    					$entry->singular .= $unpoified;
    					break;
    				case 'msgctxt':
    					$entry->context .= $unpoified;
    					break;
    				case 'msgid_plural':
    					$entry->plural .= $unpoified;
    					break;
    				case 'msgstr':
    					$entry->translations[0] .= $unpoified;
    					break;
    				case 'msgstr_plural':
    					$entry->translations[ $msgstr_index ] .= $unpoified;
    					break;
    				default:
    					return false;
    			}
    		} else {
    			return false;
    		}
    	}

    	$have_translations = false;
    	foreach ( $entry->translations as $t ) {
    		if ( $t || ( '0' === $t ) ) {
    			$have_translations = true;
    			break;
    		}
    	}
    	if ( false === $have_translations ) {
    		$entry->translations = array();
    	}

    	return array(
    		'entry'  => $entry,
    		'lineno' => $lineno,
    	);
    }
    ```

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

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

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

Helper function for read_entry

  | 
| [Translation_Entry::__construct()](https://developer.wordpress.org/reference/classes/translation_entry/__construct/)`wp-includes/pomo/entry.php` |  | 
| [PO::read_line()](https://developer.wordpress.org/reference/classes/po/read_line/)`wp-includes/pomo/po.php` |  | 
| [PO::add_comment_to_entry()](https://developer.wordpress.org/reference/classes/po/add_comment_to_entry/)`wp-includes/pomo/po.php` |  | 
| [PO::unpoify()](https://developer.wordpress.org/reference/classes/po/unpoify/)`wp-includes/pomo/po.php` |

Gives back the original string from a PO-formatted string

  |

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

## User Contributed Notes

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