Reputation: 460
I have textarea field where users can write random text. After posting it i need to put this text into json variable via php.
Something like that, text:
Lorem Ipsum is simply "dummy text" of the printing\typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
And this text must be converted into valid json variable. Any help?)
Upvotes: 0
Views: 91
Reputation: 423
I always do it with trial and error starting from the top row of keyboard and taking all characters on number keys with SHIFT Key. Than add any other chars as needed.
You can also use addslashes($str)
:
<?php
$yourText = 'Lorem Ipsum is simply "dummy text" of the printing\typesetting industry.'
jsonText = addslashes($str)
?>
Upvotes: 0
Reputation: 11689
Assuming your textarea
name is text
and that form is submitted by POST:
$data = array( 'textarea' => $_POST['text'] );
$json = json_encode( $data );
Upvotes: 2