PO::poify()
Formats a string in PO-style
Method of the class: PO{}
No Hooks.
Return
String
. the poified string
Usage
$result = PO::poify( $input_string );
- $input_string(string) (required)
- the string to format
PO::poify() PO::poify code WP 6.7.1
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; }