我有textarea字段,用户可以在其中编写随机文本。发布后我需要通过php将此文本放入json变量。
类似的东西,文字:
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.
此文本必须转换为有效的json变量。有什么帮助?)
答案 0 :(得分:2)
假设您的textarea
名称为text
且该表单由POST提交:
$data = array( 'textarea' => $_POST['text'] );
$json = json_encode( $data );
答案 1 :(得分:0)
我总是从键盘的顶行开始试错,并使用SHIFT键获取数字键上的所有字符。然后根据需要添加任何其他字符。
您还可以使用addslashes($str)
:
<?php
$yourText = 'Lorem Ipsum is simply "dummy text" of the printing\typesetting industry.'
jsonText = addslashes($str)
?>