PO::unpoify()public staticWP 1.0

Gives back the original string from a PO-formatted string

Метод класса: PO{}

Хуков нет.

Возвращает

Строку. unescaped string

Использование

$result = PO::unpoify( $input_string );
$input_string(строка) (обязательный)
PO-formatted string

Код PO::unpoify() WP 6.5.2

public static function unpoify( $input_string ) {
	$escapes               = array(
		't'  => "\t",
		'n'  => "\n",
		'r'  => "\r",
		'\\' => '\\',
	);
	$lines                 = array_map( 'trim', explode( "\n", $input_string ) );
	$lines                 = array_map( array( 'PO', 'trim_quotes' ), $lines );
	$unpoified             = '';
	$previous_is_backslash = false;
	foreach ( $lines as $line ) {
		preg_match_all( '/./u', $line, $chars );
		$chars = $chars[0];
		foreach ( $chars as $char ) {
			if ( ! $previous_is_backslash ) {
				if ( '\\' === $char ) {
					$previous_is_backslash = true;
				} else {
					$unpoified .= $char;
				}
			} else {
				$previous_is_backslash = false;
				$unpoified            .= isset( $escapes[ $char ] ) ? $escapes[ $char ] : $char;
			}
		}
	}

	// Standardize the line endings on imported content, technically PO files shouldn't contain \r.
	$unpoified = str_replace( array( "\r\n", "\r" ), "\n", $unpoified );

	return $unpoified;
}