Title: POMO_StringReader
Published: April 25, 2014
Last modified: April 28, 2025

---

# class POMO_StringReader {}

## In this article

 * [Methods](https://developer.wordpress.org/reference/classes/pomo_stringreader/?output_format=md#methods)
 * [Source](https://developer.wordpress.org/reference/classes/pomo_stringreader/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/pomo_stringreader/?output_format=md#related)

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

Provides file-like methods for manipulating a string instead of a physical file.

## 󠀁[Methods](https://developer.wordpress.org/reference/classes/pomo_stringreader/?output_format=md#methods)󠁿

| Name | Description | 
| [POMO_StringReader::__construct](https://developer.wordpress.org/reference/classes/pomo_stringreader/__construct/) | PHP5 constructor. | 
| [POMO_StringReader::length](https://developer.wordpress.org/reference/classes/pomo_stringreader/length/) | – | 
| [POMO_StringReader::POMO_StringReader](https://developer.wordpress.org/reference/classes/pomo_stringreader/pomo_stringreader/) | PHP4 constructor. — deprecated | 
| [POMO_StringReader::read](https://developer.wordpress.org/reference/classes/pomo_stringreader/read/) | – | 
| [POMO_StringReader::read_all](https://developer.wordpress.org/reference/classes/pomo_stringreader/read_all/) | – | 
| [POMO_StringReader::seekto](https://developer.wordpress.org/reference/classes/pomo_stringreader/seekto/) | – |

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

    ```php
    class POMO_StringReader extends POMO_Reader {

    	public $_str = '';

    	/**
    	 * PHP5 constructor.
    	 */
    	public function __construct( $str = '' ) {
    		parent::__construct();
    		$this->_str = $str;
    		$this->_pos = 0;
    	}

    	/**
    	 * PHP4 constructor.
    	 *
    	 * @deprecated 5.4.0 Use __construct() instead.
    	 *
    	 * @see POMO_StringReader::__construct()
    	 */
    	public function POMO_StringReader( $str = '' ) {
    		_deprecated_constructor( self::class, '5.4.0', static::class );
    		self::__construct( $str );
    	}

    	/**
    	 * @param string $bytes
    	 * @return string
    	 */
    	public function read( $bytes ) {
    		$data        = $this->substr( $this->_str, $this->_pos, $bytes );
    		$this->_pos += $bytes;
    		if ( $this->strlen( $this->_str ) < $this->_pos ) {
    			$this->_pos = $this->strlen( $this->_str );
    		}
    		return $data;
    	}

    	/**
    	 * @param int $pos
    	 * @return int
    	 */
    	public function seekto( $pos ) {
    		$this->_pos = $pos;
    		if ( $this->strlen( $this->_str ) < $this->_pos ) {
    			$this->_pos = $this->strlen( $this->_str );
    		}
    		return $this->_pos;
    	}

    	/**
    	 * @return int
    	 */
    	public function length() {
    		return $this->strlen( $this->_str );
    	}

    	/**
    	 * @return string
    	 */
    	public function read_all() {
    		return $this->substr( $this->_str, $this->_pos, $this->strlen( $this->_str ) );
    	}
    }
    ```

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

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

| Uses | Description | 
| [POMO_Reader](https://developer.wordpress.org/reference/classes/pomo_reader/)`wp-includes/pomo/streams.php` |  |

| Used by | Description | 
| [POMO_CachedFileReader](https://developer.wordpress.org/reference/classes/pomo_cachedfilereader/)`wp-includes/pomo/streams.php` |

Reads the contents of the file in the beginning.

  |

## User Contributed Notes

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