PO::poify()public staticWP 1.0

Formats a string in PO-style

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

Хуков нет.

Возвращает

Строку. the poified string

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

$result = PO::poify( $input_string );
$input_string(строка) (обязательный)
the string to format

Код PO::poify() WP 6.5.2

public static function poify( $input_string ) {
	$quote   = '"';
	$slash   = '\\';
	$newline = "\n";

	$replaces = array(
		"$slash" => "$slash$slash",
		"$quote" => "$slash$quote",
		"\t"     => '\t',
	);

	$input_string = str_replace( array_keys( $replaces ), array_values( $replaces ), $input_string );

	$po = $quote . implode( "{$slash}n{$quote}{$newline}{$quote}", explode( $newline, $input_string ) ) . $quote;
	// Add empty string on first line for readability.
	if ( str_contains( $input_string, $newline ) &&
		( substr_count( $input_string, $newline ) > 1 || substr( $input_string, -strlen( $newline ) ) !== $newline ) ) {
		$po = "$quote$quote$newline$po";
	}
	// Remove empty strings.
	$po = str_replace( "$newline$quote$quote", '', $po );
	return $po;
}