$text = "hello world
Hi Baby
Nice";
$text_line_json = text_line_json_encode( $text );
echo "<pre>";
print_r( $text_line_json );
echo "</pre>";
Last active
August 22, 2020 03:15
-
-
Save lenivene/8571963f1cfee2dce325cd025b013eb4 to your computer and use it in GitHub Desktop.
TEXT LINE TO JSON PHP FUNCTION
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function text_line_json_encode( $value, $options = 0, $depth = 512 ){ | |
$to_json = $value; | |
if( ! is_array( $value ) || ! is_object( $value ) ){ | |
$to_json = preg_split("/\r\n|\n|\r/", (string) $value ); | |
} | |
return json_encode( $to_json, $options, $depth ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment